Difference between try catch and NSSetUncaughtExceptionHandler

I tried using two methods to throw exceptions. The first is with the try trick, and the second 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 that we do not need to implement try catch blocks in each method.

The first one gets an exception, prints it, but does not crash the application .. But the second catches the exception, and causes the application to crash .

Is there a way to use the second method to throw exceptions without crashing the application.

+4
source share
1 answer

NSSetUncaughtExceptionHandler , . onUncaughtException - , - .

@try...@catch...@finally.. NSException, catch, @catch, , , @finally. @try...@catch... , .

+4

Source: https://habr.com/ru/post/1531093/


All Articles