My app includes crash reporting library that using NSSetUncaughtExceptionHandler
in order to catch the crashes.
I need to implement custom action (log crash and display alert view) before\after the crash reporting implementation.
To achieve this behavior, first I'm keep a reference to previous UncaughtExceptionHandler using NSGetUncaughtExceptionHandler()
, and than registering my custom exception handler and signals handler. In my custom handler I tried to execute previous handler before\after my custom actions, but this throws a signal SIGABRT for previousHandler(exception) (in both cases).
Here is the code example :
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");
}
- How can I execute previous handler without throws a signal ?
- Any ideas why
SignalHandler
doesn't called when system throws a signal ?