What is Exception Handling?
NSError is the most preferred way to handle the errors in Objective-C, but we can also use exception handling for exceptional cases. In this, we will use try and catch block for identifying the errors and throwing the errors out of the program without impacting the code. However, exceptions should be used sparingly for exceptional circumstances and not for routine error handling.
Syntax:
@try {
// Code that may raise an exception
}
@catch (NSException *exception) {
NSLog(@”An exception occurred: %@”, [exception reason]);
}
@finally {
// Code that will be executed regardless of whether an exception occurred
}
In this method these two blocks try and catch are used for identifying the errors in the program.
Error Handling in Objective-C
In this article, we will learn about error handling in objective C. There are different methods to handle errors in Objective-C with the help of examples and code.
Contact Us