1

The following simple code on the app's delegate on a new cocoa test project.

void onUncaughtException(NSException *exception){
    NSLog(@"Caught!!! %@", exception);
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSSetUncaughtExceptionHandler(&onUncaughtException);

    NSException *exception = [[NSException alloc]initWithName:@"exception" reason:@"exception reason here" userInfo:nil];
    @throw exception;
}

I only get single console log line with the exception name and reason, but onUncaughtException does not get called. The app continues to run without a problem.

What am I missing here? I tried this on debug and release builds with same results.

the Reverend
  • 12,305
  • 10
  • 66
  • 121

1 Answers1

0

I don't know all the ins and outs of it, but I suspect that NSApplication is intercepting it before it fails through to your handler.

Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • Yes, exceptions on the main thread of an app are not uncaught. @theReverend, see [Exception Programming Topics: Controlling a Program’s Response to Exceptions](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Exceptions/Tasks/ControllingAppResponse.html). – Ken Thomases May 13 '12 at 08:53