我的应用程序包含NSSetUncaughtExceptionHandler
用于捕获崩溃的崩溃报告库。我需要在崩溃报告实现之前\之后实现自定义操作(记录崩溃并显示警报视图)。为了实现这种行为,首先我使用 来保留对先前 UncaughtExceptionHandler 的引用NSGetUncaughtExceptionHandler()
,然后注册我的自定义异常处理程序和信号处理程序。在我的自定义处理程序中,我尝试在自定义操作之前\之后执行上一个处理程序,但这会为 previousHandler(exception) 抛出一个信号 SIGABRT(在这两种情况下)。这是代码示例:
static NSUncaughtExceptionHandler *previousHandler;
void InstallUncaughtExceptionHandler()
{
// keep reference to previous handler
previousHandler = NSGetUncaughtExceptionHandler();
// register my custom exception handler
NSSetUncaughtExceptionHandler(&HandleException);
signal(SIGABRT, SignalHandler);
signal(SIGILL, SignalHandler);
signal(SIGSEGV, SignalHandler);
signal(SIGFPE, SignalHandler);
signal(SIGBUS, SignalHandler);
signal(SIGPIPE, SignalHandler);
}
void HandleException(NSException *exception)
{
// execute previous handler
previousHandler(exception);
// my custom actions
}
void SignalHandler(int signal)
{
NSLog(@"SignalHandler");
}
- 如何在不抛出信号的情况下执行先前的处理程序?
- 任何想法为什么
SignalHandler
在系统抛出信号时不调用?