question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[JS] JS API for global handling of unhandled exceptions

See original GitHub issue

The API I envision is similar to window.onerror but not necessarily the same. This would allow us to make RCTExceptionsManager.reportUnhandledException a lot smaller (we’d move much of the code into JS to keep the current behavior) and make it easier to do custom error handling.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:31 (23 by maintainers)

github_iconTop GitHub Comments

4reactions
atticooscommented, Jan 27, 2016

Exactly @qbig

Basically

if (!__DEV__) {
  ErrorUtils.setGlobalHandler(error => {
    sentry.capture(error);
    NativeModules.BridgeReloader.reload()
  });
}

Then your BridgeReloader would be an objC module that simply calls [_bridge reload]

Or in an Android module, you just get the running activity, finish it, and restart it

@ReactMethod
public void reload() {
  Activity activity = getCurrentActivity();
  Intent intent = activity.getIntent();
  activity.finish();
  activity.startActivity(intent);
}
3reactions
qbigcommented, Jan 27, 2016

Here: https://github.com/facebook/react-native/blob/d33b554f5d4bb7856cf2fc21175bab23d8225fe4/packager/react-packager/src/Resolver/polyfills/error-guard.js

var ErrorUtils = {
  _inGuard: 0,
  _globalHandler: null,
  setGlobalHandler: function(fun) {
    ErrorUtils._globalHandler = fun;
  },
//...

‘setGlobalHandler’ would overwrite a lot of the RN behaviour (eg. RedBox in development). Understanding that we could just monkey patch globalHandler, the "" seems alarming. So maybe an API like addGlobalHandler, so that we could add custom handler without breaking the default behaviour and and without messing with “internal” variables ? @ide @satya164

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve unhandled exceptions in Node.js
There are two approaches to resolve unhandled exceptions in Node.js that are discussed below: Approach 1: Using try-catch block: We know ...
Read more >
Best Practices for Node.js Error-handling
This article will introduce you to error-handling in Node.js and ... I am going to mention dealing with unhandled promise rejections and exceptions....
Read more >
Global Error Handling in ASP.NET Core Web API
The exception handling features help us deal with the unforeseen errors which could appear in our code. To handle exceptions we can use...
Read more >
Client-side global error handling and unhandled promise ...
When a resource (such as an img or script ) fails to load, an error event using interface Event is fired at the...
Read more >
How to Handle Exceptions in JavaScript
While this is relatively simplistic in terms of error handling, it is important to note that the exception that is caught is always...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found