我的应用程序包括使用NSSetUncaughtExceptionHandler来捕获崩溃的崩溃报告库。我需要在崩溃报告实现之后实现自定义操作(日志崩溃和显示警报视图)。为了实现这种行为,首先我使用UncaughtExceptionHandler保存对以前的NSGetUncaughtExceptionHandler()的引用,而不是注册我的自定义异常处理程序和信号处理程序。在我的自定义处理程序中,我试图在自定义操作后\之后执行前面的处理程序,但这会引发用于previousHandler(异常)的信号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不调用吗?发布于 2015-11-02 08:46:27
不要注册信号处理程序。我不得不混淆一下下面显示的代码,但它来自app上的一个生产应用程序:
AppDelegate应用程序:didFinishLaunchingWithOptions:
fabricHandler = NSGetUncaughtExceptionHandler();
NSSetUncaughtExceptionHandler(&customUncaughtExceptionHandler);处理程序:
void customUncaughtExceptionHandler(NSException *exception) {
// Custom handling
if (fabricHandler) {
fabricHandler(exception);
}
}发布于 2017-12-22 09:34:34
PreviousSignalHandler可能1)重置所有设置的信号处理程序2)调用中止
原因之一是它会流产。所以你可以做你想做的所有事情,并调用上一个处理程序。
HTH
https://stackoverflow.com/questions/33473058
复制相似问题