Bug 1066175 - Use other means to handle uncaught exception when Gecko is unavailable; r=snorp

When the Gecko crash reporter is unavailable, uncaught Java exceptions can end up being ignored. We should try more ways to handle the exception.
This commit is contained in:
Jim Chen 2014-09-17 12:59:20 -04:00
parent 44773977b0
commit 11a68eae9d

View File

@ -131,6 +131,7 @@ public class GeckoAppShell
// We have static members only.
private GeckoAppShell() { }
private static Thread.UncaughtExceptionHandler systemUncaughtHandler;
private static boolean restartScheduled;
private static GeckoEditableListener editableListener;
@ -210,6 +211,8 @@ public class GeckoAppShell
public static native void dispatchMemoryPressure();
public static void registerGlobalExceptionHandler() {
systemUncaughtHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable e) {
@ -484,8 +487,19 @@ public class GeckoAppShell
// shutdown
editor.commit();
}
} finally {
} catch (final Throwable exc) {
// Report the Java crash below, even if we encounter an exception here.
}
try {
reportJavaCrash(getStackTraceString(e));
} finally {
// reportJavaCrash should have caused us to hard crash. If we're still here,
// it probably means Gecko is not loaded, and we should do something else.
// Bring up the app crashed dialog so we don't crash silently.
if (systemUncaughtHandler != null) {
systemUncaughtHandler.uncaughtException(thread, e);
}
}
}