Skip to content

Commit d3ba48b

Browse files
authored
fix: throw NSException on main thread (#188)
This helps catchers like `NSSetUncaughtExceptionHandler` get the correct info from the `NSException`
1 parent 90a074a commit d3ba48b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

NativeScript/runtime/NativeScriptException.mm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@
5656
Local<v8::String> messageV8String = message->Get();
5757
std::string messageString = tns::ToString(isolate, messageV8String);
5858
NSString* name = [NSString stringWithFormat:@"NativeScript encountered a fatal error: %s\n at \n%s", messageString.c_str(), stackTrace.c_str()];
59-
NSException* objcException = [NSException exceptionWithName:name reason:nil userInfo:@{ @"sender": @"onUncaughtError" }];
60-
61-
NSLog(@"***** Fatal JavaScript exception - application has been terminated. *****\n");
62-
NSLog(@"%@", [objcException description]);
63-
@throw objcException;
59+
// we throw the exception on main thread
60+
// otherwise it seems that when getting NSException info from NSSetUncaughtExceptionHandler
61+
// we are missing almost all data. No explanation for why yet
62+
dispatch_async(dispatch_get_main_queue(), ^(void) {
63+
NSException* objcException = [NSException exceptionWithName:name reason:nil userInfo:@{ @"sender": @"onUncaughtError" }];
64+
65+
NSLog(@"***** Fatal JavaScript exception - application has been terminated. *****\n");
66+
NSLog(@"%@", [objcException description]);
67+
@throw objcException;
68+
});
6469
} else {
6570
NSLog(@"NativeScript discarding uncaught JS exception!");
6671
}

0 commit comments

Comments
 (0)