Skip to content

Commit

Permalink
fix(ios): implement signal exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Jul 25, 2019
1 parent 55ce0e1 commit 9f67416
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiExceptionHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
*/

#import "TiExceptionHandler.h"
#import "APSAnalytics.h"
#import "TiApp.h"
#import "TiBase.h"

#include <execinfo.h>
#include <signal.h>

static void TiUncaughtExceptionHandler(NSException *exception);
static void TiSignalHandler(int signal);

static NSUncaughtExceptionHandler *prevUncaughtExceptionHandler = NULL;

Expand All @@ -26,6 +30,13 @@ + (TiExceptionHandler *)defaultExceptionHandler
defaultExceptionHandler = [[self alloc] init];
prevUncaughtExceptionHandler = NSGetUncaughtExceptionHandler();
NSSetUncaughtExceptionHandler(&TiUncaughtExceptionHandler);

signal(SIGABRT, TiSignalHandler);
signal(SIGILL, TiSignalHandler);
signal(SIGSEGV, TiSignalHandler);
signal(SIGFPE, TiSignalHandler);
signal(SIGBUS, TiSignalHandler);
signal(SIGPIPE, TiSignalHandler);
});
return defaultExceptionHandler;
}
Expand Down Expand Up @@ -218,3 +229,11 @@ static void TiUncaughtExceptionHandler(NSException *exception)
[NSThread exit];
}
}

static void TiSignalHandler(int code)
{
NSException *exception = [NSException exceptionWithName:@"SIGNAL_ERROR" reason:[NSString stringWithFormat:@"signal error code: %d", code] userInfo:nil];
[[TiExceptionHandler defaultExceptionHandler] reportException:exception];
[[APSAnalytics sharedInstance] flush];
signal(code, SIG_DFL);
}

0 comments on commit 9f67416

Please sign in to comment.