NativeScript / ios-jsc

NativeScript for iOS using JavaScriptCore

Home Page:http://docs.nativescript.org/runtimes/ios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iOS exceptions are not getting caught by uncaughtErrorEvent

tsonevn opened this issue · comments

@KkevinLi commented on Wed Dec 05 2018

Environment

✔ Component tns-core-modules has 5.0.5 version and is up to date.
✔ Component tns-android has 5.0.0 version and is up to date.
✔ Component tns-ios has 5.0.0 version and is up to date.

Describe the bug

No uncaughtError event is raised for native iOS errors such as NSInvalidArgumentException.

To Reproduce

I am using the following to test:

  static iosCrashTest1() {
    console.log("IOS Crash Test 1");
    const foo: NSArray<any> = NSArray.alloc();
    foo.objectAtIndex(3);
  }

Expected behavior

Expected an uncaughtErrorEvent to be thrown (logging purposes). Right now I get a Javascript call stack followed by *** Terminating app due to uncaught exception 'NSInvalidArgumentException' ...***


@tsonevn commented on Wed Dec 05 2018

Hi @KkevinLi,
We have checked your case and found that the iOS exceptions are not getting caught by uncaughtErrorEvent, because of a missing feature. Regarding that, I will mark the issue as a feature request and will move it in the ios-runtime repository, where we can keep the discussion about this feature.
Also, there is an experimental branch, which enables this functionality in NativeScript. You can find it here.

Hi @KkevinLi, thank you for raising this issue. We've also thought about rethrowing Objective-C exceptions to JavaScript before. In fact there's a branch that experiments with it. We may include it in some of the next versions if there's demand for it but the reasons we decided to not merge the branch was that generally Apple advise developers to not continue execution after catching an Objective-C exception.

Thank you, I will check out that branch.

I agree that the application should not continue running after a C exception, but how would we be able to log these issues in production without knowing they are occuring? Is there a recommended approach to this? ( I want to know this is happening so I can fix them rather than just knowing the app has crashed )

@KkevinLi The fix is released as a @next version in NPM, feel free to give it a try and tell us if it works as expected. Please have in mind that currently it works only on real devices. We've logged this limitation as a known issue (#1044).