npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tcbs/react-native-exception-handler

v1.0.0

Published

Maintained fork of react-native-exception-handler by TCBS

Downloads

148

Readme

@tcbs/react-native-exception-handler

npm downloads license

A React Native module to register global JavaScript and Native exception handlers
to gracefully handle fatal and non-fatal crashes in production apps.


Fork Notice

This package is a maintained fork of
react-native-exception-handler originally created by Atul R (@a7ul).

TCBS maintains this fork to:

  • Support modern React Native versions
  • Apply stability and bug fixes
  • Ensure long-term maintenance
  • Keep the API backward compatible

The original MIT license and contributor credits are fully preserved.


Why this library?

In a typical React Native app:

  • DEV mode → Red screen with stack trace
  • PRODUCTION (bundled) mode → App crashes silently 😐

This library allows you to:

  1. Capture uncaught JS exceptions
  2. Capture Native crashes (Android & iOS)
  3. Show a graceful message to users
  4. Report crashes to analytics / backend
  5. Avoid abrupt app termination without context

What’s Supported

Exception Types

| Type | Description | |----|-----------| | JS Exceptions | Errors from JavaScript / React code | | Native Exceptions | Crashes from native Android / iOS code |

⚠️ Native exceptions are critical.
UI rendering via JS is not possible once a native crash occurs.


Installation

npm install @tcbs/react-native-exception-handler
# or
yarn add @tcbs/react-native-exception-handler

React Native ≥ 0.60

Autolinking is supported. No manual linking required.


Migration from original package

No code changes needed.

- react-native-exception-handler
+ @tcbs/react-native-exception-handler

All APIs remain the same.


Usage

Handling JavaScript Exceptions

import {
  setJSExceptionHandler,
  getJSExceptionHandler,
} from '@tcbs/react-native-exception-handler';

setJSExceptionHandler((error, isFatal) => {
  console.log(error, isFatal);
});

// Optional: override Red Screen in DEV mode
setJSExceptionHandler(
  (error, isFatal) => {
    console.log(error, isFatal);
  },
  true
);

const currentHandler = getJSExceptionHandler();

Handling Native Exceptions

import { setNativeExceptionHandler } from '@tcbs/react-native-exception-handler';

setNativeExceptionHandler((exceptionString) => {
  console.log(exceptionString);
});

Advanced Usage

setNativeExceptionHandler(
  exceptionString => {
    // Custom native error handling
  },
  true,   // forceAppQuit (Android only, default true)
  false   // executeDefaultHandler
);

| Parameter | Platform | Description | | ----------------------- | ------------- | -------------------------------------- | | forceAppQuit | Android | Force app exit after crash | | executeDefaultHandler | Android + iOS | Execute previously registered handlers |


Important Notes

  • setNativeExceptionHandler only works in bundled / release mode
  • In DEV mode, the Red Screen will still appear
  • Native crashes cannot show JS-based UI

Customization

JavaScript Exception Handler

You can show alerts, dialogs, log errors, or restart the app.

setJSExceptionHandler((error, isFatal) => {
  if (isFatal) {
    // Show alert / send logs / restart app
  }
});

Android Native Exception Customization (Recommended)

Override native handling inside MainApplication.java:

ReactNativeExceptionHandlerModule.setNativeExceptionHandler(
  (thread, throwable, originalHandler) -> {
    // Custom native crash handling
  }
);

iOS Native Exception Customization

In AppDelegate.m:

[ReactNativeExceptionHandler replaceNativeExceptionHandlerBlock:
 ^(NSException *exception, NSString *readableException) {

  // Show alert to user

  [NSTimer scheduledTimerWithTimeInterval:4.0
                                   target:[ReactNativeExceptionHandler class]
                                 selector:@selector(releaseExceptionHold)
                                 userInfo:nil
                                  repeats:NO];
}];

📌 iOS apps cannot restart programmatically after a native crash.


Example: Restart App on Fatal Error

import { Alert } from 'react-native';
import RNRestart from 'react-native-restart';
import { setJSExceptionHandler } from '@tcbs/react-native-exception-handler';

setJSExceptionHandler((error, isFatal) => {
  if (isFatal) {
    Alert.alert(
      'Unexpected error',
      'The app will restart.',
      [{ text: 'Restart', onPress: () => RNRestart.Restart() }]
    );
  }
});

Known Issues

react-native-navigation (Wix)

Set forceAppQuit to false:

setNativeExceptionHandler(nativeErrorCallback, false);

Preserve Previously Registered Handlers

If other analytics SDKs register global handlers:

setNativeExceptionHandler(callback, true, true);

Testing Native Crashes

Use the test module from the original author:

https://github.com/master-atul/rn-test-exception-handler

It intentionally triggers native crashes for validation.


Contributors (Original Project)

  • Atul R
  • Zeh Fernando
  • Fred Chasen
  • Damien Solimando
  • Gustavo Fão Valvassori
  • and many more ❤️

(Full list preserved from upstream project)


TCBS Maintainers

  • Subrata Das (@subrata1977)

License

MIT License Same as the original project.


Credits

This project stands on the solid foundation built by @a7ul and the open-source community.


Made with ❤️ by Subrata

Peace ✌️


---