Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the NSError message in iOS?

I am having the method in my view controller as shown below:

- (void)parser:(PaymentTermsLibxmlParser *)parser encounteredError:(NSError *)error {     NSLog("error occured"); } 

Here I need to show the Actual error message in the NSError in my alert can any one suggest how to get it.

like image 658
Monish Kumar Avatar asked Aug 10 '10 07:08

Monish Kumar


People also ask

What is NSError in Swift?

Information about an error condition including a domain, a domain-specific error code, and application-specific information.

What is NSError domain?

The core attributes of an NSError object—or, simply, an error object—are an error domain, a domain-specific error code, and a “user info” dictionary containing objects related to the error, most significantly description and recovery strings.

What is made up of NSError object?

The core attributes of an NSError object are an error domain (represented by a string), a domain-specific error code and a user info dictionary containing application specific information.

What is the latest version of Objective C?

The latest version of objective C is 2.0.


2 Answers

Normally you'll want to use [error localizedDescription] to get the text to show to the user.

Read the NSError documentation for more options.

For simple logging when developing, you can do NSLog(@"Error: %@", error). (That will give you 'localizedDescription' and everything else on your log in Xcode.)

like image 101
jtbandes Avatar answered Sep 19 '22 10:09

jtbandes


To get error message only, use:

NSString *msg = [error localizedDescription]; 

But for logging more details, use %@ format, like:

NSLog(@"Error: %@", error); 
like image 20
mkodamati Avatar answered Sep 22 '22 10:09

mkodamati