Skip to content

Introduce a setting for auto catching exceptions when calling JS method native #1119

Closed

Description

@vtrifonov

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
}

Activity

  1. added this to the 4.2.0 milestone on Jul 20, 2018
  2. self-assigned this
    on Jul 20, 2018
  3. self-assigned this
    on Jul 20, 2018
  4. IAMtheIAM commented on Sep 3, 2018

    @IAMtheIAM

    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?

  5. NickIliev commented on Sep 4, 2018

    @NickIliev

    @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

  6. vtrifonov commented on Sep 4, 2018

    @vtrifonov
    ContributorAuthor

    @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.

  7. IAMtheIAM commented on Sep 4, 2018

    @IAMtheIAM

    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.

  8. soscler commented on Nov 13, 2020

    @soscler

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions