I have tried two methods for catching the exceptions. First one is with a try catch and the second one is with the following code in Appdelegate.
void onUncaughtException(NSException* exception)
{
//save exception details
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&onUncaughtException);
}
The advantage of the second method is we don need to implement try catch blocks in each and every method.
The first one catches the exception, prints it but does not crash the application.. But the second one catches the exception and crashes the application.
Is there any way to use the second method to catch exceptions without crashing the application.
NSSetUncaughtExceptionHandler
Sets the top-level error-handling function where you can perform last-minute logging before the program terminates. in the onUncaughtException
you can do something before crash, but app do crash finally.
@try...@catch...@finally..
is to try to catch possible NSException, if catch, run in the @catch
block code, no matter if catch, code will run in @finally
block code. Using @try...@catch...
will not cause crash finally, this may be the main difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With