Android-runtime: Introduce a setting for auto catching exceptions when calling JS method native

Created on 20 Jul 2018  路  5Comments  路  Source: NativeScript/android-runtime

We need a setting to enable and disable catching exceptions when calling the callJSMethodNative method. If enabled those exceptions will be caught an logged without propagating them.
The default value of that setting is false, so if such an error occurs it won't be caught and if not handled somewhere else will crash the application.
The flag is disabled by default, so if you want to enable it you should add in your app/package.json file this:

{
    ...
    "discardUncaughtJsExceptions": true
}
feature

Most helpful comment

@IAMtheIAM the setting should be placed in the application package.json located in the app folder

example app/package.json

{
  "android": {
    "v8Flags": "--expose_gc"
  },
  "main": "app.js",
  "name": "tns-template-hello-world-ts",
  "version": "4.1.0",
  "discardUncaughtJsExceptions":true
}

Documentation section here

All 5 comments

Where in package.json does this go? Top level, under nativescript: {}, somewhere else? Also, how do we know if the flag was picked up by the app or not?

@IAMtheIAM the setting should be placed in the application package.json located in the app folder

example app/package.json

{
  "android": {
    "v8Flags": "--expose_gc"
  },
  "main": "app.js",
  "name": "tns-template-hello-world-ts",
  "version": "4.1.0",
  "discardUncaughtJsExceptions":true
}

Documentation section here

@IAMtheIAM to test whether you have enabled the setting you can add throw new Error("MyError"); in a button click handler and check whether the app will crash or not when pressing the button. If the discardUncaughtJsExceptions is enabled you should only see the error in the log, if not the app would crash and show the error activity screen.

Thanks guys, that is exactly the info I was looking for. I recommend it be added to some docs somewhere, just as explained here to me. I read the Nativescript 4.2 update notice but was not sure which level it should be added to.

with nativescript angular the file is located in src/package.json

Was this page helpful?
0 / 5 - 0 ratings