I’m trying to catch exceptions on my Mac app so that I can log them in a custom log file. I’m implementing the exception handler like this:
void uncaughtExceptionHandler(NSException *exception) {
NSLog(@"It Works!");
}
And I’m setting it in my -applicationDidFinishLaunching: method like this:
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
Then I cause an exception to test it like this:
[[NSArray arrayWithObject:@"object"] objectAtIndex:1];
The exception gets logged to the console, but my exception handler is not being called.
Any ideas?
The solution is to use the
ExceptionHandlingframework. Here’s how I did it:In
-applicationDidFinishLaunching:Then in my App Delegate class I implement to two delegate methods,
Now I can catch all exceptions!