From 1d6ed1e205b031e4a1a96e8f47f5f5ec7928f80a Mon Sep 17 00:00:00 2001 From: Instabug Date: Mon, 11 Aug 2025 13:12:03 +0000 Subject: [PATCH] Handle IllegalStateException in sendNativeFatalCrash to prevent unhandled fatal crash --- .../RNInstabugExampleCrashReportingModule.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleCrashReportingModule.java b/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleCrashReportingModule.java index 4ccb7ad3c..7749f8679 100644 --- a/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleCrashReportingModule.java +++ b/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleCrashReportingModule.java @@ -37,9 +37,18 @@ public void sendNativeNonFatal(final String exceptionObject) { @ReactMethod public void sendNativeFatalCrash() { - throw new IllegalStateException("Unhandled IllegalStateException from Instabug Test App"); + try { + throw new IllegalStateException("Unhandled IllegalStateException from Instabug Test App"); + } catch (IllegalStateException e) { + @ReactMethod + public void sendNativeFatalCrash() { + try { + throw new IllegalStateException("Unhandled IllegalStateException from Instabug Test App"); + } catch (IllegalStateException e) { + // Report the exception using CrashReporting or log it, instead of crashing the app + CrashReporting.report(e); + } } - @ReactMethod public void sendANR() { sendHang(20000);