A modern React Native library for global error handling (JavaScript + native) with TurboModules support and cross-platform compatibility.
π¬ See live demos of iOS and Android crash handling in action!
- π₯ Modern Architecture: Built with TurboModules for React Native 0.68+
- π± Cross-Platform: Full iOS and Android support
- π― Dual Exception Handling: Catches both JS and native exceptions
- π§ Highly Customizable: Configurable options for different platforms
- π Crash Simulation: Built-in crash testing for development
- π¨ Custom Error UI: Platform-specific error screens with restart functionality
- β‘ TypeScript Support: Full TypeScript definitions included
In React Native apps, uncaught exceptions behave differently based on the environment:
- In DEV mode: You get a helpful Red Screen error showing the stack trace
- In production (bundled) mode: The app simply quits without any message π±
This creates a poor user experience where users don't know:
- What went wrong
- Whether they should restart the app
- If their data was saved
This library solves this by:
- Catching unhandled exceptions before the app crashes
- Allowing you to show a graceful error message to users
- Enabling error reporting to your development team
- Providing restart capabilities for recovery
- Getting Started - Installation and setup
- Usage Guide - JS exception handling
- Native Crash Handling - Platform-specific native handlers
- API Reference - Complete API documentation
- Testing & Simulation - simulateNativeCrash and testing
- Analytics Integration - Sentry, Crashlytics, custom services
- Customization - Custom error screens
- Troubleshooting - Common issues and solutions
- Migration Guide - From react-native-exception-handler
npm install react-native-global-exception-handler
# or
yarn add react-native-global-exception-handlerRequires React Native 0.68+ (TurboModules & auto-linking)
Works with both:
- Legacy Architecture (Old Architecture)
- New Architecture (TurboModules + Fabric)
No additional configuration needed; the correct bindings are auto-selected at build time.
import { setJSExceptionHandler } from 'react-native-global-exception-handler';
// Basic setup
setJSExceptionHandler((error, isFatal) => {
console.log('JS Exception:', error);
if (isFatal) {
// Handle fatal errors - maybe show restart dialog
} else {
// Handle non-fatal errors - maybe just log them
}
});
// Advanced setup with dev mode control
setJSExceptionHandler(
(error, isFatal) => {
// Your error handler
},
true // allowedInDevMode: true = enable in dev (shows instead of RedBox)
);import { setNativeExceptionHandler } from 'react-native-global-exception-handler';
// Basic setup with default options
setNativeExceptionHandler((errorString) => {
console.log('Native Exception:', errorString);
// Send to crash reporting service
});
// Advanced setup with platform-specific options
setNativeExceptionHandler(
(errorString) => {
console.log('Native Exception:', errorString);
},
{
forceAppToQuit: true, // Android: Force app to quit after error (default: true)
callPreviouslyDefinedHandler: false // Call previous exception handler (default: false)
}
);See the contributing guide to learn how to contribute to the repository and the development workflow.
This project is inspired by the original work in react-native-exception-handler created by its original authors and community of contributors. Many foundational ideas (global JS/native handler approach, restart patterns, native popup customization) originated there.
MIT
Made with β€οΈ for the React Native community