问题
我正在编写一个Cocoa应用程序,我想提出异常会使应用程序崩溃.
我的应用程序委托中有以下行:
[NSException raise:NSInternalInconsistencyException format:@"This should crash the application."];
abort();
Run Code Online (Sandbox Code Playgroud)
问题是,他们没有关闭应用程序 - 消息只是记录到控制台,应用程序继续它的快乐方式.
据我了解,例外的全部内容是它们在特殊情况下被解雇.在这种情况下,我希望应用程序以明显的方式退出.这不会发生.
我试过的
我试过了:
-(void)applicationDidFinishLaunching:(NSNotification *)note
// ...
[self performSelectorOnMainThread:@selector(crash) withObject:nil waitUntilDone:YES];
}
-(void)crash {
[NSException raise:NSInternalInconsistencyException format:@"This should crash the application."];
abort();
}
Run Code Online (Sandbox Code Playgroud)
哪个不起作用
-(void)applicationDidFinishLaunching:(NSNotification *)note
// ...
[self performSelectorInBackground:@selector(crash) withObject:nil];
}
-(void)crash {
[NSException raise:NSInternalInconsistencyException format:@"This should crash the application."];
abort();
}
Run Code Online (Sandbox Code Playgroud)
相当令人困惑的是,它按预期工作.
这是怎么回事?我究竟做错了什么?