Maintained fork of react-native-exception-handler by TCBS
npm install @tcbs/react-native-exception-handlerA React Native module to register global JavaScript and Native exception handlers
to gracefully handle fatal and non-fatal crashes in production apps.
---
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.
---
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
---
| 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.
---
``bash`
npm install @tcbs/react-native-exception-handleror
yarn add @tcbs/react-native-exception-handler
Autolinking is supported.
No manual linking required.
---
No code changes needed.
`diff`
- react-native-exception-handler
+ @tcbs/react-native-exception-handler
All APIs remain the same.
---
`js
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();
`
---
`js
import { setNativeExceptionHandler } from '@tcbs/react-native-exception-handler';
setNativeExceptionHandler((exceptionString) => {
console.log(exceptionString);
});
`
#### Advanced Usage
`js`
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 |
---
* setNativeExceptionHandler only works in bundled / release mode
* In DEV mode, the Red Screen will still appear
* Native crashes cannot show JS-based UI
---
You can show alerts, dialogs, log errors, or restart the app.
`js`
setJSExceptionHandler((error, isFatal) => {
if (isFatal) {
// Show alert / send logs / restart app
}
});
---
Override native handling inside MainApplication.java:
`java`
ReactNativeExceptionHandlerModule.setNativeExceptionHandler(
(thread, throwable, originalHandler) -> {
// Custom native crash handling
}
);
---
In AppDelegate.m:
`objc
[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.
---
`js
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() }]
);
}
});
`
---
Set forceAppQuit to false:
`js`
setNativeExceptionHandler(nativeErrorCallback, false);
---
If other analytics SDKs register global handlers:
`js`
setNativeExceptionHandler(callback, true, true);
---
Use the test module from the original author:
https://github.com/master-atul/rn-test-exception-handler
It intentionally triggers native crashes for validation.
---
* Atul R
* Zeh Fernando
* Fred Chasen
* Damien Solimando
* Gustavo Fão Valvassori
* and many more ❤️
(Full list preserved from upstream project)
---
* Subrata Das (@subrata1977)
---
MIT License
Same as the original project.
---
This project stands on the solid foundation built by
@a7ul and the open-source community.
---
Made with ❤️ by Subrata
Peace ✌️
``
---