Skip to content

Commit

Permalink
fix: throw NSException on main thread (#188)
Browse files Browse the repository at this point in the history
This helps catchers like `NSSetUncaughtExceptionHandler` get the correct info from the `NSException`
  • Loading branch information
farfromrefug authored Jan 5, 2023
1 parent 90a074a commit d3ba48b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions NativeScript/runtime/NativeScriptException.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@
Local<v8::String> messageV8String = message->Get();
std::string messageString = tns::ToString(isolate, messageV8String);
NSString* name = [NSString stringWithFormat:@"NativeScript encountered a fatal error: %s\n at \n%s", messageString.c_str(), stackTrace.c_str()];
NSException* objcException = [NSException exceptionWithName:name reason:nil userInfo:@{ @"sender": @"onUncaughtError" }];

NSLog(@"***** Fatal JavaScript exception - application has been terminated. *****\n");
NSLog(@"%@", [objcException description]);
@throw objcException;
// we throw the exception on main thread
// otherwise it seems that when getting NSException info from NSSetUncaughtExceptionHandler
// we are missing almost all data. No explanation for why yet
dispatch_async(dispatch_get_main_queue(), ^(void) {
NSException* objcException = [NSException exceptionWithName:name reason:nil userInfo:@{ @"sender": @"onUncaughtError" }];

NSLog(@"***** Fatal JavaScript exception - application has been terminated. *****\n");
NSLog(@"%@", [objcException description]);
@throw objcException;
});
} else {
NSLog(@"NativeScript discarding uncaught JS exception!");
}
Expand Down

0 comments on commit d3ba48b

Please sign in to comment.