The Problem
I'm writing a Cocoa application and I want to raise exceptions that will crash the application noisily.
I have the following lines in my application delegate:
[NSException raise:NSInternalInconsistencyException format:@"This should crash the application."];
abort();
The problem is, they don't bring down the application - the message is just logged to the console and the app carries on it's merry way.
As I understand it, the whole point of exceptions is that they're fired under exceptional circumstances. In these circumstances, I want the application to quit in an obvious way. And this doesn't happen.
What I've tried
I've tried:
-(void)applicationDidFinishLaunching:(NSNotification *)note
// ...
[self performSelectorOnMainThread:@selector(crash) withObject:nil waitUntilDone:YES];
}
-(void)crash {
[NSException raise:NSInternalInconsistencyException format:@"This should crash the application."];
abort();
}
which doesn't work and
-(void)applicationDidFinishLaunching:(NSNotification *)note
// ...
[self performSelectorInBackground:@selector(crash) withObject:nil];
}
-(void)crash {
[NSException raise:NSInternalInconsistencyException format:@"This should crash the application."];
abort();
}
which, rather confusingly, works as expected.
What's going on? What am I doing wrong?