Bug 958706 - Make generated JNI wrappers handle uncaught exceptions; r=blassey
authorJim Chen <nchen@mozilla.com>
Fri, 17 Jan 2014 23:32:25 -0600
changeset 164125 a7cf0019d9491d3cd4dae65db8b5ada3e229963e
parent 164124 0ed7f1bad6e301e9bdd7fa968846eaaca5226eef
child 164126 3635e6adde70c47a55a34c0c56c79636fd11a354
push id26026
push userphilringnalda@gmail.com
push dateSat, 18 Jan 2014 23:17:27 +0000
treeherdermozilla-central@61fd0f987cf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs958706
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 958706 - Make generated JNI wrappers handle uncaught exceptions; r=blassey This patch adds AndroidBridge::HandleUncaughtException calls to generated JNI wrappers. Also, the JNI annotation now accepts the noThrow flag to indicate that the JNI caller wishes to handle Exceptions manually.
build/annotationProcessors/AnnotationInfo.java
build/annotationProcessors/CodeGenerator.java
build/annotationProcessors/utils/GeneratableElementIterator.java
widget/android/GeneratedJNIWrappers.cpp
--- a/build/annotationProcessors/AnnotationInfo.java
+++ b/build/annotationProcessors/AnnotationInfo.java
@@ -6,15 +6,18 @@ package org.mozilla.gecko.annotationProc
 
 /**
  * Object holding annotation data. Used by GeneratableElementIterator.
  */
 public class AnnotationInfo {
     public final String wrapperName;
     public final boolean isStatic;
     public final boolean isMultithreaded;
+    public final boolean noThrow;
 
-    public AnnotationInfo(String aWrapperName, boolean aIsStatic, boolean aIsMultithreaded) {
+    public AnnotationInfo(String aWrapperName, boolean aIsStatic, boolean aIsMultithreaded,
+                          boolean aNoThrow) {
         wrapperName = aWrapperName;
         isStatic = aIsStatic;
         isMultithreaded = aIsMultithreaded;
+        noThrow = aNoThrow;
     }
 }
--- a/build/annotationProcessors/CodeGenerator.java
+++ b/build/annotationProcessors/CodeGenerator.java
@@ -65,21 +65,17 @@ public class CodeGenerator {
      * Emit a static method which takes an instance of the class being wrapped and returns an instance
      * of the C++ wrapper class backed by that object.
      */
     private void generateWrapperMethod() {
         headerPublic.append("    static ").append(mCClassName).append("* Wrap(jobject obj);\n" +
                 "    ").append(mCClassName).append("(jobject obj, JNIEnv* env) : AutoGlobalWrappedJavaObject(obj, env) {};\n");
 
         wrapperMethodBodies.append("\n").append(mCClassName).append("* ").append(mCClassName).append("::Wrap(jobject obj) {\n" +
-                "    JNIEnv *env = GetJNIForThread();\n\n" +
-                "    if (!env) {\n" +
-                "        ALOG_BRIDGE(\"Aborted: No env - %s\", __PRETTY_FUNCTION__);\n" +
-                "        return nullptr;\n" +
-                "    }\n\n" +
+                "    JNIEnv *env = GetJNIForThread();\n" +
                 "    ").append(mCClassName).append("* ret = new ").append(mCClassName).append("(obj, env);\n" +
                 "    env->DeleteLocalRef(obj);\n" +
                 "    return ret;\n" +
                 "}\n");
     }
 
     private void generateMemberCommon(Member theMethod, String aCMethodName, Class<?> aClass) {
         ensureClassHeaderAndStartup(aClass);
@@ -109,17 +105,20 @@ public class CodeGenerator {
         // Get the C++ method signature for this method.
         String implementationSignature = Utils.getCImplementationMethodSignature(parameterTypes, returnType, CMethodName, mCClassName);
         String headerSignature = Utils.getCHeaderMethodSignature(parameterTypes, theMethod.getParameterAnnotations(), returnType, CMethodName, mCClassName, shallGenerateStatic);
 
         // Add the header signature to the header file.
         writeSignatureToHeader(headerSignature);
 
         // Use the implementation signature to generate the method body...
-        writeMethodBody(implementationSignature, CMethodName, theMethod, mClassToWrap, aMethodTuple.mAnnotationInfo.isStatic, aMethodTuple.mAnnotationInfo.isMultithreaded);
+        writeMethodBody(implementationSignature, CMethodName, theMethod, mClassToWrap,
+            aMethodTuple.mAnnotationInfo.isStatic,
+            aMethodTuple.mAnnotationInfo.isMultithreaded,
+            aMethodTuple.mAnnotationInfo.noThrow);
     }
 
     private void generateGetterOrSetterBody(Class<?> aFieldType, String aFieldName, boolean aIsFieldStatic, boolean isSetter) {
         StringBuilder argumentContent = null;
 
         if (isSetter) {
             Class<?>[] setterArguments = new Class<?>[]{aFieldType};
             // Marshall the argument..
@@ -224,17 +223,19 @@ public class CodeGenerator {
         // Slice off the "void " from the start of the constructor declaration.
         headerSignature = headerSignature.substring(5);
         implementationSignature = implementationSignature.substring(5);
 
         // Add the header signatures to the header file.
         writeSignatureToHeader(headerSignature);
 
         // Use the implementation signature to generate the method body...
-        writeCtorBody(implementationSignature, theCtor, aCtorTuple.mAnnotationInfo.isMultithreaded);
+        writeCtorBody(implementationSignature, theCtor,
+            aCtorTuple.mAnnotationInfo.isMultithreaded,
+            aCtorTuple.mAnnotationInfo.noThrow);
 
         if (theCtor.getParameterTypes().length == 0) {
             mHasEncounteredDefaultConstructor = true;
         }
     }
 
     /**
      * Writes the appropriate header and startup code to ensure the existence of a reference to the
@@ -281,30 +282,27 @@ public class CodeGenerator {
                            .append(" {\n");
 
         wrapperMethodBodies.append("    JNIEnv *env = ");
         if (!aIsThreaded) {
             wrapperMethodBodies.append("AndroidBridge::GetJNIEnv();\n");
         } else {
             wrapperMethodBodies.append("GetJNIForThread();\n");
         }
-        wrapperMethodBodies.append("    if (!env) {\n" +
-                                   "        ALOG_BRIDGE(\"Aborted: No env - %s\", __PRETTY_FUNCTION__);\n" +
-                                   "        return").append(Utils.getFailureReturnForType(returnType)).append(";\n" +
-                "    }\n\n");
     }
 
     /**
      * Write out the appropriate JNI frame pushing boilerplate for a call to the member provided (
      * which must be a constructor or method).
      *
      * @param aMethod A constructor/method being wrapped.
      * @param aIsObjectReturningMethod Does the method being wrapped return an object?
      */
-    private void writeFramePushBoilerplate(Member aMethod, boolean aIsObjectReturningMethod) {
+    private void writeFramePushBoilerplate(Member aMethod,
+            boolean aIsObjectReturningMethod, boolean aNoThrow) {
         if (aMethod instanceof Field) {
             throw new IllegalArgumentException("Tried to push frame for a FIELD?!");
         }
 
         Method m;
         Constructor c;
 
         Class<?> returnType;
@@ -320,23 +318,28 @@ public class CodeGenerator {
             localReferencesNeeded = Utils.enumerateReferenceArguments(c.getParameterTypes());
         }
 
         // Determine the number of local refs required for our local frame..
         // AutoLocalJNIFrame is not applicable here due to it's inability to handle return values.
         if (aIsObjectReturningMethod) {
             localReferencesNeeded++;
         }
-        wrapperMethodBodies.append("    if (env->PushLocalFrame(").append(localReferencesNeeded).append(") != 0) {\n" +
-                "        ALOG_BRIDGE(\"Exceptional exit of: %s\", __PRETTY_FUNCTION__);\n" +
-                "        env->ExceptionDescribe();\n"+
-                "        env->ExceptionClear();\n" +
-                "        return").append(Utils.getFailureReturnForType(returnType)).append(";\n" +
+        wrapperMethodBodies.append(
+                "    if (env->PushLocalFrame(").append(localReferencesNeeded).append(") != 0) {\n");
+        if (!aNoThrow) {
+            wrapperMethodBodies.append(
+                "        AndroidBridge::HandleUncaughtException(env);\n" +
+                "        MOZ_ASSUME_UNREACHABLE(\"Exception should have caused crash.\");\n");
+        } else {
+            wrapperMethodBodies.append(
+                "        return").append(Utils.getFailureReturnForType(returnType)).append(";\n");
+        }
+        wrapperMethodBodies.append(
                 "    }\n\n");
-
     }
 
     private StringBuilder getArgumentMarshalling(Class<?>[] argumentTypes) {
         StringBuilder argumentContent = new StringBuilder();
 
         // If we have >2 arguments, use the jvalue[] calling approach.
         argumentContent.append(", ");
         if (argumentTypes.length > 2) {
@@ -371,22 +374,23 @@ public class CodeGenerator {
             if (needsNewline) {
                 wrapperMethodBodies.append('\n');
             }
         }
 
         return argumentContent;
     }
 
-    private void writeCtorBody(String implementationSignature, Constructor theCtor, boolean aIsThreaded) {
+    private void writeCtorBody(String implementationSignature, Constructor theCtor,
+            boolean aIsThreaded, boolean aNoThrow) {
         Class<?>[] argumentTypes = theCtor.getParameterTypes();
 
         writeFunctionStartupBoilerPlate(implementationSignature, Void.class, false, aIsThreaded);
 
-        writeFramePushBoilerplate(theCtor, false);
+        writeFramePushBoilerplate(theCtor, false, aNoThrow);
 
         // Marshall arguments for this constructor, if any...
         boolean hasArguments = argumentTypes.length != 0;
 
         StringBuilder argumentContent = new StringBuilder();
         if (hasArguments) {
             argumentContent = getArgumentMarshalling(argumentTypes);
         }
@@ -415,25 +419,27 @@ public class CodeGenerator {
      * Generates the method body of the C++ wrapper function for the Java method indicated.
      *
      * @param methodSignature The previously-generated C++ method signature for the method to be
      *                        generated.
      * @param aCMethodName    The C++ method name for the method to be generated.
      * @param aMethod         The Java method to be wrapped by the C++ method being generated.
      * @param aClass          The Java class to which the method belongs.
      */
-    private void writeMethodBody(String methodSignature, String aCMethodName, Method aMethod, Class<?> aClass, boolean aIsStaticBridgeMethod, boolean aIsMultithreaded) {
+    private void writeMethodBody(String methodSignature, String aCMethodName, Method aMethod,
+            Class<?> aClass, boolean aIsStaticBridgeMethod, boolean aIsMultithreaded,
+            boolean aNoThrow) {
         Class<?>[] argumentTypes = aMethod.getParameterTypes();
         Class<?> returnType = aMethod.getReturnType();
 
         writeFunctionStartupBoilerPlate(methodSignature, returnType, aIsStaticBridgeMethod, aIsMultithreaded);
 
         boolean isObjectReturningMethod = !returnType.getCanonicalName().equals("void") && Utils.isObjectType(returnType);
 
-        writeFramePushBoilerplate(aMethod, isObjectReturningMethod);
+        writeFramePushBoilerplate(aMethod, isObjectReturningMethod, aNoThrow);
 
         // Marshall arguments, if we have any.
         boolean hasArguments = argumentTypes.length != 0;
 
         // We buffer the arguments to the call separately to avoid needing to repeatedly iterate the
         // argument list while building this line. In the coming code block, we simultaneously
         // construct any argument marshalling code (Creation of jstrings, placement of arguments
         // into an argument array, etc. and the actual argument list passed to the function (in
@@ -472,26 +478,22 @@ public class CodeGenerator {
             // call.
             wrapperMethodBodies.append(Utils.getClassReferenceName(aClass)).append(", ");
         }
 
         wrapperMethodBodies.append(mMembersToIds.get(aMethod));
 
         // Tack on the arguments, if any..
         wrapperMethodBodies.append(argumentContent)
-                           .append(");\n\n");
+                           .append(");\n");
 
-        // Check for exception and return the failure value..
-        wrapperMethodBodies.append("    if (env->ExceptionCheck()) {\n" +
-                                   "        ALOG_BRIDGE(\"Exceptional exit of: %s\", __PRETTY_FUNCTION__);\n" +
-                                   "        env->ExceptionDescribe();\n" +
-                                   "        env->ExceptionClear();\n" +
-                                   "        env->PopLocalFrame(nullptr);\n" +
-                                   "        return").append(Utils.getFailureReturnForType(returnType)).append(";\n" +
-                                   "    }\n\n");
+        // Check for exception and crash if any...
+        if (!aNoThrow) {
+            wrapperMethodBodies.append("    AndroidBridge::HandleUncaughtException(env);\n");
+        }
 
         // If we're returning an object, pop the callee's stack frame extracting our ref as the return
         // value.
         if (isObjectReturningMethod) {
             wrapperMethodBodies.append("    ")
                                .append(Utils.getCReturnType(returnType))
                                .append(" ret = static_cast<").append(Utils.getCReturnType(returnType)).append(">(env->PopLocalFrame(temp));\n" +
                                        "    return ret;\n");
--- a/build/annotationProcessors/utils/GeneratableElementIterator.java
+++ b/build/annotationProcessors/utils/GeneratableElementIterator.java
@@ -70,31 +70,38 @@ public class GeneratableElementIterator 
             for (Annotation annotation : ((AnnotatedElement) candidateElement).getDeclaredAnnotations()) {
                 // WrappedJNIMethod has parameters. Use Reflection to obtain them.
                 Class<? extends Annotation> annotationType = annotation.annotationType();
                 final String annotationTypeName = annotationType.getName();
                 if (annotationTypeName.equals("org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI")) {
                     String stubName = null;
                     boolean isStaticStub = false;
                     boolean isMultithreadedStub = false;
+                    boolean noThrow = false;
                     try {
                         // Determine the explicitly-given name of the stub to generate, if any.
                         final Method stubNameMethod = annotationType.getDeclaredMethod("stubName");
                         stubNameMethod.setAccessible(true);
                         stubName = (String) stubNameMethod.invoke(annotation);
 
                         // Detemine if the generated stub should be static.
                         final Method staticStubMethod = annotationType.getDeclaredMethod("generateStatic");
                         staticStubMethod.setAccessible(true);
                         isStaticStub = (Boolean) staticStubMethod.invoke(annotation);
 
                         // Determine if the generated stub is to allow calls from multiple threads.
                         final Method multithreadedStubMethod = annotationType.getDeclaredMethod("allowMultithread");
                         multithreadedStubMethod.setAccessible(true);
                         isMultithreadedStub = (Boolean) multithreadedStubMethod.invoke(annotation);
+
+                        // Determine if ignoring exceptions
+                        final Method noThrowMethod = annotationType.getDeclaredMethod("noThrow");
+                        noThrowMethod.setAccessible(true);
+                        noThrow = (Boolean) noThrowMethod.invoke(annotation);
+
                     } catch (NoSuchMethodException e) {
                         System.err.println("Unable to find expected field on WrapElementForJNI annotation. Did the signature change?");
                         e.printStackTrace(System.err);
                         System.exit(3);
                     } catch (IllegalAccessException e) {
                         System.err.println("IllegalAccessException reading fields on WrapElementForJNI annotation. Seems the semantics of Reflection have changed...");
                         e.printStackTrace(System.err);
                         System.exit(4);
@@ -105,26 +112,28 @@ public class GeneratableElementIterator 
                     }
 
                     // If the method name was not explicitly given in the annotation generate one...
                     if (stubName.isEmpty()) {
                         String aMethodName = candidateElement.getName();
                         stubName = aMethodName.substring(0, 1).toUpperCase() + aMethodName.substring(1);
                     }
 
-                    AnnotationInfo annotationInfo = new AnnotationInfo(stubName, isStaticStub, isMultithreadedStub);
+                    AnnotationInfo annotationInfo = new AnnotationInfo(
+                        stubName, isStaticStub, isMultithreadedStub, noThrow);
                     mNextReturnValue = new AnnotatableEntity(candidateElement, annotationInfo);
                     return;
                 }
             }
 
             // If no annotation found, we might be expected to generate anyway using default arguments,
             // thanks to the "Generate everything" annotation.
             if (mIterateEveryEntry) {
-                AnnotationInfo annotationInfo = new AnnotationInfo(candidateElement.getName(), false, false);
+                AnnotationInfo annotationInfo = new AnnotationInfo(
+                    candidateElement.getName(), false, false, false);
                 mNextReturnValue = new AnnotatableEntity(candidateElement, annotationInfo);
                 return;
             }
         }
         mNextReturnValue = null;
     }
 
     @Override
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -171,2268 +171,1090 @@ void GeckoAppShell::InitStubs(JNIEnv *jE
     jUnlockScreenOrientation = getStaticMethod("unlockScreenOrientation", "()V");
     jUnregisterSurfaceTextureFrameListener = getStaticMethod("unregisterSurfaceTextureFrameListener", "(Ljava/lang/Object;)V");
     jVibrate1 = getStaticMethod("vibrate", "(J)V");
     jVibrateA = getStaticMethod("vibrate", "([JI)V");
 }
 
 GeckoAppShell* GeckoAppShell::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     GeckoAppShell* ret = new GeckoAppShell(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 void GeckoAppShell::AcknowledgeEvent() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jAcknowledgeEvent);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::AddPluginViewWrapper(jobject a0, jfloat a1, jfloat a2, jfloat a3, jfloat a4, bool a5) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[6];
     args[0].l = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
     args[4].f = a4;
     args[5].z = a5;
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jAddPluginViewWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::AlertsProgressListener_OnProgress(const nsAString& a0, int64_t a1, int64_t a2, const nsAString& a3) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].j = a1;
     args[2].j = a2;
     args[3].l = AndroidBridge::NewJavaString(env, a3);
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jAlertsProgressListener_OnProgress, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::CancelVibrate() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jCancelVibrate);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::CheckURIVisited(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jCheckURIVisited, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::ClearMessageList(int32_t a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jClearMessageList, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::CloseCamera() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jCloseCamera);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::CloseNotification(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jCloseNotification, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::CreateMessageListWrapper(int64_t a0, int64_t a1, jobjectArray a2, int32_t a3, int32_t a4, bool a5, int32_t a6) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[7];
     args[0].j = a0;
     args[1].j = a1;
     args[2].l = a2;
     args[3].i = a3;
     args[4].i = a4;
     args[5].z = a5;
     args[6].i = a6;
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jCreateMessageListWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::CreateShortcut(const nsAString& a0, const nsAString& a1, const nsAString& a2, const nsAString& a3) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(4) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].l = AndroidBridge::NewJavaString(env, a1);
     args[2].l = AndroidBridge::NewJavaString(env, a2);
     args[3].l = AndroidBridge::NewJavaString(env, a3);
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jCreateShortcut, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::DeleteMessageWrapper(int32_t a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jDeleteMessageWrapper, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::DisableBatteryNotifications() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableBatteryNotifications);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::DisableNetworkNotifications() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableNetworkNotifications);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::DisableScreenOrientationNotifications() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableScreenOrientationNotifications);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::DisableSensor(int32_t a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::EnableBatteryNotifications() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableBatteryNotifications);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::EnableLocation(bool a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::EnableLocationHighAccuracy(bool a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocationHighAccuracy, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::EnableNetworkNotifications() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableNetworkNotifications);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::EnableScreenOrientationNotifications() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableScreenOrientationNotifications);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::EnableSensor(int32_t a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jobject GeckoAppShell::GetContext() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetContext);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jdoubleArray GeckoAppShell::GetCurrentBatteryInformationWrapper() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetCurrentBatteryInformationWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jdoubleArray ret = static_cast<jdoubleArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jdoubleArray GeckoAppShell::GetCurrentNetworkInformationWrapper() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetCurrentNetworkInformationWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jdoubleArray ret = static_cast<jdoubleArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jfloat GeckoAppShell::GetDensity() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return 0.0;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jfloat temp = env->CallStaticFloatMethod(mGeckoAppShellClass, jGetDensity);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return 0.0;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 int32_t GeckoAppShell::GetDpiWrapper() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return 0;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     int32_t temp = env->CallStaticIntMethod(mGeckoAppShellClass, jGetDpiWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return 0;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 jstring GeckoAppShell::GetExtensionFromMimeTypeWrapper(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetExtensionFromMimeTypeWrapper, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jobjectArray GeckoAppShell::GetHandlersForMimeTypeWrapper(const nsAString& a0, const nsAString& a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(3) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
     jstring j1 = AndroidBridge::NewJavaString(env, a1);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetHandlersForMimeTypeWrapper, j0, j1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobjectArray ret = static_cast<jobjectArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jobjectArray GeckoAppShell::GetHandlersForURLWrapper(const nsAString& a0, const nsAString& a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(3) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
     jstring j1 = AndroidBridge::NewJavaString(env, a1);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetHandlersForURLWrapper, j0, j1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobjectArray ret = static_cast<jobjectArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jbyteArray GeckoAppShell::GetIconForExtensionWrapper(const nsAString& a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetIconForExtensionWrapper, j0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jbyteArray ret = static_cast<jbyteArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoAppShell::GetMessageWrapper(int32_t a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jGetMessageWrapper, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jstring GeckoAppShell::GetMimeTypeFromExtensionsWrapper(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetMimeTypeFromExtensionsWrapper, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoAppShell::GetNextMessageInListWrapper(int32_t a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jGetNextMessageInListWrapper, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jstring GeckoAppShell::GetProxyForURIWrapper(const nsAString& a0, const nsAString& a1, const nsAString& a2, int32_t a3) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(4) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].l = AndroidBridge::NewJavaString(env, a1);
     args[2].l = AndroidBridge::NewJavaString(env, a2);
     args[3].i = a3;
 
     jobject temp = env->CallStaticObjectMethodA(mGeckoAppShellClass, jGetProxyForURIWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 int32_t GeckoAppShell::GetScreenDepthWrapper() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return 0;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     int32_t temp = env->CallStaticIntMethod(mGeckoAppShellClass, jGetScreenDepthWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return 0;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 int16_t GeckoAppShell::GetScreenOrientationWrapper() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return 0;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     int16_t temp = env->CallStaticShortMethod(mGeckoAppShellClass, jGetScreenOrientationWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return 0;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 bool GeckoAppShell::GetShowPasswordSetting() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jGetShowPasswordSetting);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 jintArray GeckoAppShell::GetSystemColoursWrapper() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetSystemColoursWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jintArray ret = static_cast<jintArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jstring GeckoAppShell::HandleGeckoMessageWrapper(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jHandleGeckoMessageWrapper, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoAppShell::HandleUncaughtException(jobject a0, jthrowable a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
         return;
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jHandleUncaughtException, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::HideProgressDialog() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jHideProgressDialog);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jintArray GeckoAppShell::InitCameraWrapper(const nsAString& a0, int32_t a1, int32_t a2, int32_t a3) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].i = a1;
     args[2].i = a2;
     args[3].i = a3;
 
     jobject temp = env->CallStaticObjectMethodA(mGeckoAppShellClass, jInitCameraWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jintArray ret = static_cast<jintArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 bool GeckoAppShell::IsNetworkLinkKnown() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsNetworkLinkKnown);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 bool GeckoAppShell::IsNetworkLinkUp() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsNetworkLinkUp);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 bool GeckoAppShell::IsTablet() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsTablet);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 void GeckoAppShell::KillAnyZombies() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jKillAnyZombies);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jclass GeckoAppShell::LoadPluginClass(const nsAString& a0, const nsAString& a1) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(3) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
     jstring j1 = AndroidBridge::NewJavaString(env, a1);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jLoadPluginClass, j0, j1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jclass ret = static_cast<jclass>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoAppShell::LockScreenOrientation(int32_t a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jLockScreenOrientation, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::MarkURIVisited(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jMarkURIVisited, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::MoveTaskToBack() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jMoveTaskToBack);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 int32_t GeckoAppShell::NetworkLinkType() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return 0;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     int32_t temp = env->CallStaticIntMethod(mGeckoAppShellClass, jNetworkLinkType);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return 0;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 void GeckoAppShell::NotifyDefaultPrevented(bool a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jNotifyDefaultPrevented, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::NotifyIME(int32_t a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jNotifyIME, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::NotifyIMEChange(const nsAString& a0, int32_t a1, int32_t a2, int32_t a3) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].i = a1;
     args[2].i = a2;
     args[3].i = a3;
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jNotifyIMEChange, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::NotifyIMEContext(int32_t a0, const nsAString& a1, const nsAString& a2, const nsAString& a3) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(3) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].i = a0;
     args[1].l = AndroidBridge::NewJavaString(env, a1);
     args[2].l = AndroidBridge::NewJavaString(env, a2);
     args[3].l = AndroidBridge::NewJavaString(env, a3);
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jNotifyIMEContext, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::NotifyWakeLockChanged(const nsAString& a0, const nsAString& a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
     jstring j1 = AndroidBridge::NewJavaString(env, a1);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jNotifyWakeLockChanged, j0, j1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::NotifyXreExit() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jNotifyXreExit);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 bool GeckoAppShell::OpenUriExternal(const nsAString& a0, const nsAString& a1, const nsAString& a2, const nsAString& a3, const nsAString& a4, const nsAString& a5) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(6) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[6];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].l = AndroidBridge::NewJavaString(env, a1);
     args[2].l = AndroidBridge::NewJavaString(env, a2);
     args[3].l = AndroidBridge::NewJavaString(env, a3);
     args[4].l = AndroidBridge::NewJavaString(env, a4);
     args[5].l = AndroidBridge::NewJavaString(env, a5);
 
     bool temp = env->CallStaticBooleanMethodA(mGeckoAppShellClass, jOpenUriExternal, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 void GeckoAppShell::PerformHapticFeedback(bool a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jPerformHapticFeedback, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 bool GeckoAppShell::PumpMessageLoop() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jPumpMessageLoop);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 void GeckoAppShell::RegisterSurfaceTextureFrameListener(jobject a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jRegisterSurfaceTextureFrameListener, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::RemovePluginView(jobject a0, bool a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jRemovePluginView, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::ScanMedia(const nsAString& a0, const nsAString& a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
     jstring j1 = AndroidBridge::NewJavaString(env, a1);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jScanMedia, j0, j1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::ScheduleRestart() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jScheduleRestart);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::SendMessageWrapper(const nsAString& a0, const nsAString& a1, int32_t a2) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[3];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].l = AndroidBridge::NewJavaString(env, a1);
     args[2].i = a2;
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jSendMessageWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::SetFullScreen(bool a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jSetFullScreen, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::SetKeepScreenOn(bool a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jSetKeepScreenOn, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::SetURITitle(const nsAString& a0, const nsAString& a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
     jstring j1 = AndroidBridge::NewJavaString(env, a1);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jSetURITitle, j0, j1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::ShowAlertNotificationWrapper(const nsAString& a0, const nsAString& a1, const nsAString& a2, const nsAString& a3, const nsAString& a4) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(5) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[5];
     args[0].l = AndroidBridge::NewJavaString(env, a0);
     args[1].l = AndroidBridge::NewJavaString(env, a1);
     args[2].l = AndroidBridge::NewJavaString(env, a2);
     args[3].l = AndroidBridge::NewJavaString(env, a3);
     args[4].l = AndroidBridge::NewJavaString(env, a4);
 
     env->CallStaticVoidMethodA(mGeckoAppShellClass, jShowAlertNotificationWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::ShowFilePickerAsyncWrapper(const nsAString& a0, int64_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jShowFilePickerAsyncWrapper, j0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jstring GeckoAppShell::ShowFilePickerForExtensionsWrapper(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jShowFilePickerForExtensionsWrapper, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jstring GeckoAppShell::ShowFilePickerForMimeTypeWrapper(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jShowFilePickerForMimeTypeWrapper, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoAppShell::ShowInputMethodPicker() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jShowInputMethodPicker);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 bool GeckoAppShell::UnlockProfile() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallStaticBooleanMethod(mGeckoAppShellClass, jUnlockProfile);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 void GeckoAppShell::UnlockScreenOrientation() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jUnlockScreenOrientation);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::UnregisterSurfaceTextureFrameListener(jobject a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jUnregisterSurfaceTextureFrameListener, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::Vibrate1(int64_t a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jVibrate1, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoAppShell::VibrateA(jlongArray a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoAppShellClass, jVibrateA, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 jclass JavaDomKeyLocation::mDomKeyLocationClass = 0;
 jmethodID JavaDomKeyLocation::jvalueOf = 0;
 jmethodID JavaDomKeyLocation::jvalues = 0;
 jfieldID JavaDomKeyLocation::jDOM_KEY_LOCATION_JOYSTICK = 0;
 jfieldID JavaDomKeyLocation::jDOM_KEY_LOCATION_LEFT = 0;
 jfieldID JavaDomKeyLocation::jDOM_KEY_LOCATION_MOBILE = 0;
@@ -2452,152 +1274,81 @@ void JavaDomKeyLocation::InitStubs(JNIEn
     jDOM_KEY_LOCATION_NUMPAD = getStaticField("DOM_KEY_LOCATION_NUMPAD", "Lorg/mozilla/gecko/GeckoEvent$DomKeyLocation;");
     jDOM_KEY_LOCATION_RIGHT = getStaticField("DOM_KEY_LOCATION_RIGHT", "Lorg/mozilla/gecko/GeckoEvent$DomKeyLocation;");
     jDOM_KEY_LOCATION_STANDARD = getStaticField("DOM_KEY_LOCATION_STANDARD", "Lorg/mozilla/gecko/GeckoEvent$DomKeyLocation;");
     jvalue = getField("value", "I");
 }
 
 JavaDomKeyLocation* JavaDomKeyLocation::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     JavaDomKeyLocation* ret = new JavaDomKeyLocation(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 jobject JavaDomKeyLocation::valueOf(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     jobject temp = env->CallStaticObjectMethod(mDomKeyLocationClass, jvalueOf, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jobjectArray JavaDomKeyLocation::values() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mDomKeyLocationClass, jvalues);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobjectArray ret = static_cast<jobjectArray>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jobject JavaDomKeyLocation::getDOM_KEY_LOCATION_JOYSTICK() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetStaticObjectField(mDomKeyLocationClass, jDOM_KEY_LOCATION_JOYSTICK));
 }
 
 jobject JavaDomKeyLocation::getDOM_KEY_LOCATION_LEFT() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetStaticObjectField(mDomKeyLocationClass, jDOM_KEY_LOCATION_LEFT));
 }
 
 jobject JavaDomKeyLocation::getDOM_KEY_LOCATION_MOBILE() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetStaticObjectField(mDomKeyLocationClass, jDOM_KEY_LOCATION_MOBILE));
 }
 
 jobject JavaDomKeyLocation::getDOM_KEY_LOCATION_NUMPAD() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetStaticObjectField(mDomKeyLocationClass, jDOM_KEY_LOCATION_NUMPAD));
 }
 
 jobject JavaDomKeyLocation::getDOM_KEY_LOCATION_RIGHT() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetStaticObjectField(mDomKeyLocationClass, jDOM_KEY_LOCATION_RIGHT));
 }
 
 jobject JavaDomKeyLocation::getDOM_KEY_LOCATION_STANDARD() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetStaticObjectField(mDomKeyLocationClass, jDOM_KEY_LOCATION_STANDARD));
 }
 
 int32_t JavaDomKeyLocation::getvalue() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     return env->GetIntField(wrapped_obj, jvalue);
 }
 jclass GeckoJavaSampler::mGeckoJavaSamplerClass = 0;
 jmethodID GeckoJavaSampler::jGetFrameNameJavaProfilingWrapper = 0;
 jmethodID GeckoJavaSampler::jGetSampleTimeJavaProfiling = 0;
 jmethodID GeckoJavaSampler::jGetThreadNameJavaProfilingWrapper = 0;
 jmethodID GeckoJavaSampler::jPauseJavaProfiling = 0;
 jmethodID GeckoJavaSampler::jStartJavaProfiling = 0;
@@ -2613,221 +1364,110 @@ void GeckoJavaSampler::InitStubs(JNIEnv 
     jPauseJavaProfiling = getStaticMethod("pause", "()V");
     jStartJavaProfiling = getStaticMethod("start", "(II)V");
     jStopJavaProfiling = getStaticMethod("stop", "()V");
     jUnpauseJavaProfiling = getStaticMethod("unpause", "()V");
 }
 
 GeckoJavaSampler* GeckoJavaSampler::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     GeckoJavaSampler* ret = new GeckoJavaSampler(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 jstring GeckoJavaSampler::GetFrameNameJavaProfilingWrapper(int32_t a0, int32_t a1, int32_t a2) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[3];
     args[0].i = a0;
     args[1].i = a1;
     args[2].i = a2;
 
     jobject temp = env->CallStaticObjectMethodA(mGeckoJavaSamplerClass, jGetFrameNameJavaProfilingWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jdouble GeckoJavaSampler::GetSampleTimeJavaProfiling(int32_t a0, int32_t a1) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return 0.0;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jdouble temp = env->CallStaticDoubleMethod(mGeckoJavaSamplerClass, jGetSampleTimeJavaProfiling, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return 0.0;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 jstring GeckoJavaSampler::GetThreadNameJavaProfilingWrapper(int32_t a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mGeckoJavaSamplerClass, jGetThreadNameJavaProfilingWrapper, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoJavaSampler::PauseJavaProfiling() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoJavaSamplerClass, jPauseJavaProfiling);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoJavaSampler::StartJavaProfiling(int32_t a0, int32_t a1) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoJavaSamplerClass, jStartJavaProfiling, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoJavaSampler::StopJavaProfiling() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoJavaSamplerClass, jStopJavaProfiling);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoJavaSampler::UnpauseJavaProfiling() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mGeckoJavaSamplerClass, jUnpauseJavaProfiling);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 jclass SurfaceBits::mSurfaceBitsClass = 0;
 jmethodID SurfaceBits::jSurfaceBits = 0;
 jfieldID SurfaceBits::jbuffer = 0;
 jfieldID SurfaceBits::jformat = 0;
 jfieldID SurfaceBits::jheight = 0;
 jfieldID SurfaceBits::jwidth = 0;
@@ -2839,175 +1479,101 @@ void SurfaceBits::InitStubs(JNIEnv *jEnv
     jbuffer = getField("buffer", "Ljava/nio/ByteBuffer;");
     jformat = getField("format", "I");
     jheight = getField("height", "I");
     jwidth = getField("width", "I");
 }
 
 SurfaceBits* SurfaceBits::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     SurfaceBits* ret = new SurfaceBits(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 SurfaceBits::SurfaceBits() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     Init(env->NewObject(mSurfaceBitsClass, jSurfaceBits), env);
     env->PopLocalFrame(nullptr);
 }
 
 jobject SurfaceBits::getbuffer() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetObjectField(wrapped_obj, jbuffer));
 }
 
 void SurfaceBits::setbuffer(jobject a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetObjectField(wrapped_obj, jbuffer, a0);
 }
 
 int32_t SurfaceBits::getformat() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     return env->GetIntField(wrapped_obj, jformat);
 }
 
 void SurfaceBits::setformat(int32_t a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetIntField(wrapped_obj, jformat, a0);
 }
 
 int32_t SurfaceBits::getheight() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     return env->GetIntField(wrapped_obj, jheight);
 }
 
 void SurfaceBits::setheight(int32_t a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetIntField(wrapped_obj, jheight, a0);
 }
 
 int32_t SurfaceBits::getwidth() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     return env->GetIntField(wrapped_obj, jwidth);
 }
 
 void SurfaceBits::setwidth(int32_t a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetIntField(wrapped_obj, jwidth, a0);
 }
 jclass ThumbnailHelper::mThumbnailHelperClass = 0;
 jmethodID ThumbnailHelper::jSendThumbnail = 0;
 void ThumbnailHelper::InitStubs(JNIEnv *jEnv) {
     initInit();
 
     mThumbnailHelperClass = getClassGlobalRef("org/mozilla/gecko/ThumbnailHelper");
     jSendThumbnail = getStaticMethod("notifyThumbnail", "(Ljava/nio/ByteBuffer;IZ)V");
 }
 
 ThumbnailHelper* ThumbnailHelper::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     ThumbnailHelper* ret = new ThumbnailHelper(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 void ThumbnailHelper::SendThumbnail(jobject a0, int32_t a1, bool a2) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[3];
     args[0].l = a0;
     args[1].i = a1;
     args[2].z = a2;
 
     env->CallStaticVoidMethodA(mThumbnailHelperClass, jSendThumbnail, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 jclass DisplayPortMetrics::mDisplayPortMetricsClass = 0;
 jmethodID DisplayPortMetrics::jDisplayPortMetrics = 0;
 jfieldID DisplayPortMetrics::jMPosition = 0;
 jfieldID DisplayPortMetrics::jResolution = 0;
 void DisplayPortMetrics::InitStubs(JNIEnv *jEnv) {
     initInit();
@@ -3015,117 +1581,73 @@ void DisplayPortMetrics::InitStubs(JNIEn
     mDisplayPortMetricsClass = getClassGlobalRef("org/mozilla/gecko/gfx/DisplayPortMetrics");
     jDisplayPortMetrics = getMethod("<init>", "(FFFFF)V");
     jMPosition = getField("mPosition", "Landroid/graphics/RectF;");
     jResolution = getField("resolution", "F");
 }
 
 DisplayPortMetrics* DisplayPortMetrics::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     DisplayPortMetrics* ret = new DisplayPortMetrics(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 DisplayPortMetrics::DisplayPortMetrics(jfloat a0, jfloat a1, jfloat a2, jfloat a3, jfloat a4) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[5];
     args[0].f = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
     args[4].f = a4;
 
     Init(env->NewObjectA(mDisplayPortMetricsClass, jDisplayPortMetrics, args), env);
     env->PopLocalFrame(nullptr);
 }
 
 jobject DisplayPortMetrics::getMPosition() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     return static_cast<jobject>(env->GetObjectField(wrapped_obj, jMPosition));
 }
 
 jfloat DisplayPortMetrics::getResolution() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jResolution);
 }
 jclass GLController::mGLControllerClass = 0;
 jmethodID GLController::jCreateEGLSurfaceForCompositorWrapper = 0;
 void GLController::InitStubs(JNIEnv *jEnv) {
     initInit();
 
     mGLControllerClass = getClassGlobalRef("org/mozilla/gecko/gfx/GLController");
     jCreateEGLSurfaceForCompositorWrapper = getMethod("createEGLSurfaceForCompositor", "()Ljavax/microedition/khronos/egl/EGLSurface;");
 }
 
 GLController* GLController::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     GLController* ret = new GLController(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 jobject GLController::CreateEGLSurfaceForCompositorWrapper() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallObjectMethod(wrapped_obj, jCreateEGLSurfaceForCompositorWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 jclass GeckoLayerClient::mGeckoLayerClientClass = 0;
 jmethodID GeckoLayerClient::jActivateProgram = 0;
 jmethodID GeckoLayerClient::jContentDocumentChanged = 0;
 jmethodID GeckoLayerClient::jCreateFrame = 0;
 jmethodID GeckoLayerClient::jDeactivateProgram = 0;
@@ -3150,316 +1672,168 @@ void GeckoLayerClient::InitStubs(JNIEnv 
     jSetFirstPaintViewport = getMethod("setFirstPaintViewport", "(FFFFFFF)V");
     jSetPageRect = getMethod("setPageRect", "(FFFF)V");
     jSyncFrameMetrics = getMethod("syncFrameMetrics", "(FFFFFFFZIIIIFZ)Lorg/mozilla/gecko/gfx/ViewTransform;");
     jSyncViewportInfo = getMethod("syncViewportInfo", "(IIIIFZ)Lorg/mozilla/gecko/gfx/ViewTransform;");
 }
 
 GeckoLayerClient* GeckoLayerClient::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     GeckoLayerClient* ret = new GeckoLayerClient(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 void GeckoLayerClient::ActivateProgram() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jActivateProgram);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoLayerClient::ContentDocumentChanged() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jContentDocumentChanged);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jobject GeckoLayerClient::CreateFrame() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallObjectMethod(wrapped_obj, jCreateFrame);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoLayerClient::DeactivateProgram() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jDeactivateProgram);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jobject GeckoLayerClient::GetDisplayPort(bool a0, bool a1, int32_t a2, jobject a3) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].z = a0;
     args[1].z = a1;
     args[2].i = a2;
     args[3].l = a3;
 
     jobject temp = env->CallObjectMethodA(wrapped_obj, jGetDisplayPort, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 
 bool GeckoLayerClient::IsContentDocumentDisplayed() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallBooleanMethod(wrapped_obj, jIsContentDocumentDisplayed);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 jobject GeckoLayerClient::ProgressiveUpdateCallback(bool a0, jfloat a1, jfloat a2, jfloat a3, jfloat a4, jfloat a5, bool a6) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[7];
     args[0].z = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
     args[4].f = a4;
     args[5].f = a5;
     args[6].z = a6;
 
     jobject temp = env->CallObjectMethodA(wrapped_obj, jProgressiveUpdateCallback, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 
 void GeckoLayerClient::SetFirstPaintViewport(jfloat a0, jfloat a1, jfloat a2, jfloat a3, jfloat a4, jfloat a5, jfloat a6) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[7];
     args[0].f = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
     args[4].f = a4;
     args[5].f = a5;
     args[6].f = a6;
 
     env->CallVoidMethodA(wrapped_obj, jSetFirstPaintViewport, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void GeckoLayerClient::SetPageRect(jfloat a0, jfloat a1, jfloat a2, jfloat a3) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[4];
     args[0].f = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
 
     env->CallVoidMethodA(wrapped_obj, jSetPageRect, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jobject GeckoLayerClient::SyncFrameMetrics(jfloat a0, jfloat a1, jfloat a2, jfloat a3, jfloat a4, jfloat a5, jfloat a6, bool a7, int32_t a8, int32_t a9, int32_t a10, int32_t a11, jfloat a12, bool a13) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[14];
     args[0].f = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
     args[4].f = a4;
@@ -3469,98 +1843,62 @@ jobject GeckoLayerClient::SyncFrameMetri
     args[8].i = a8;
     args[9].i = a9;
     args[10].i = a10;
     args[11].i = a11;
     args[12].f = a12;
     args[13].z = a13;
 
     jobject temp = env->CallObjectMethodA(wrapped_obj, jSyncFrameMetrics, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 
 jobject GeckoLayerClient::SyncViewportInfo(int32_t a0, int32_t a1, int32_t a2, int32_t a3, jfloat a4, bool a5) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[6];
     args[0].i = a0;
     args[1].i = a1;
     args[2].i = a2;
     args[3].i = a3;
     args[4].f = a4;
     args[5].z = a5;
 
     jobject temp = env->CallObjectMethodA(wrapped_obj, jSyncViewportInfo, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 jclass ImmutableViewportMetrics::mImmutableViewportMetricsClass = 0;
 jmethodID ImmutableViewportMetrics::jImmutableViewportMetrics = 0;
 void ImmutableViewportMetrics::InitStubs(JNIEnv *jEnv) {
     initInit();
 
     mImmutableViewportMetricsClass = getClassGlobalRef("org/mozilla/gecko/gfx/ImmutableViewportMetrics");
     jImmutableViewportMetrics = getMethod("<init>", "(FFFFFFFFFFFFF)V");
 }
 
 ImmutableViewportMetrics* ImmutableViewportMetrics::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     ImmutableViewportMetrics* ret = new ImmutableViewportMetrics(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 ImmutableViewportMetrics::ImmutableViewportMetrics(jfloat a0, jfloat a1, jfloat a2, jfloat a3, jfloat a4, jfloat a5, jfloat a6, jfloat a7, jfloat a8, jfloat a9, jfloat a10, jfloat a11, jfloat a12) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[13];
     args[0].f = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
     args[4].f = a4;
@@ -3582,136 +1920,79 @@ void LayerView::InitStubs(JNIEnv *jEnv) 
     initInit();
 
     mLayerViewClass = getClassGlobalRef("org/mozilla/gecko/gfx/LayerView");
     jRegisterCompositorWrapper = getStaticMethod("registerCxxCompositor", "()Lorg/mozilla/gecko/gfx/GLController;");
 }
 
 LayerView* LayerView::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     LayerView* ret = new LayerView(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 jobject LayerView::RegisterCompositorWrapper() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mLayerViewClass, jRegisterCompositorWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 jclass NativePanZoomController::mNativePanZoomControllerClass = 0;
 jmethodID NativePanZoomController::jPostDelayedCallbackWrapper = 0;
 jmethodID NativePanZoomController::jRequestContentRepaintWrapper = 0;
 void NativePanZoomController::InitStubs(JNIEnv *jEnv) {
     initInit();
 
     mNativePanZoomControllerClass = getClassGlobalRef("org/mozilla/gecko/gfx/NativePanZoomController");
     jPostDelayedCallbackWrapper = getMethod("postDelayedCallback", "(J)V");
     jRequestContentRepaintWrapper = getMethod("requestContentRepaint", "(FFFFF)V");
 }
 
 NativePanZoomController* NativePanZoomController::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     NativePanZoomController* ret = new NativePanZoomController(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 void NativePanZoomController::PostDelayedCallbackWrapper(int64_t a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jPostDelayedCallbackWrapper, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void NativePanZoomController::RequestContentRepaintWrapper(jfloat a0, jfloat a1, jfloat a2, jfloat a3, jfloat a4) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[5];
     args[0].f = a0;
     args[1].f = a1;
     args[2].f = a2;
     args[3].f = a3;
     args[4].f = a4;
 
     env->CallVoidMethodA(wrapped_obj, jRequestContentRepaintWrapper, args);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 jclass ProgressiveUpdateData::mProgressiveUpdateDataClass = 0;
 jmethodID ProgressiveUpdateData::jProgressiveUpdateData = 0;
 jmethodID ProgressiveUpdateData::jsetViewport = 0;
 jfieldID ProgressiveUpdateData::jabort = 0;
 jfieldID ProgressiveUpdateData::jheight = 0;
 jfieldID ProgressiveUpdateData::jscale = 0;
@@ -3729,189 +2010,101 @@ void ProgressiveUpdateData::InitStubs(JN
     jscale = getField("scale", "F");
     jwidth = getField("width", "F");
     jx = getField("x", "F");
     jy = getField("y", "F");
 }
 
 ProgressiveUpdateData* ProgressiveUpdateData::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     ProgressiveUpdateData* ret = new ProgressiveUpdateData(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 ProgressiveUpdateData::ProgressiveUpdateData() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     Init(env->NewObject(mProgressiveUpdateDataClass, jProgressiveUpdateData), env);
     env->PopLocalFrame(nullptr);
 }
 
 void ProgressiveUpdateData::setViewport(jobject a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jsetViewport, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 bool ProgressiveUpdateData::getabort() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     return env->GetBooleanField(wrapped_obj, jabort);
 }
 
 void ProgressiveUpdateData::setabort(bool a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetBooleanField(wrapped_obj, jabort, a0);
 }
 
 jfloat ProgressiveUpdateData::getheight() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jheight);
 }
 
 void ProgressiveUpdateData::setheight(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jheight, a0);
 }
 
 jfloat ProgressiveUpdateData::getscale() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jscale);
 }
 
 void ProgressiveUpdateData::setscale(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jscale, a0);
 }
 
 jfloat ProgressiveUpdateData::getwidth() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jwidth);
 }
 
 void ProgressiveUpdateData::setwidth(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jwidth, a0);
 }
 
 jfloat ProgressiveUpdateData::getx() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jx);
 }
 
 void ProgressiveUpdateData::setx(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jx, a0);
 }
 
 jfloat ProgressiveUpdateData::gety() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jy);
 }
 
 void ProgressiveUpdateData::sety(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jy, a0);
 }
 jclass ViewTransform::mViewTransformClass = 0;
 jmethodID ViewTransform::jViewTransform = 0;
 jfieldID ViewTransform::jfixedLayerMarginBottom = 0;
 jfieldID ViewTransform::jfixedLayerMarginLeft = 0;
 jfieldID ViewTransform::jfixedLayerMarginRight = 0;
 jfieldID ViewTransform::jfixedLayerMarginTop = 0;
@@ -3933,275 +2126,151 @@ void ViewTransform::InitStubs(JNIEnv *jE
     joffsetY = getField("offsetY", "F");
     jscale = getField("scale", "F");
     jx = getField("x", "F");
     jy = getField("y", "F");
 }
 
 ViewTransform* ViewTransform::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     ViewTransform* ret = new ViewTransform(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 ViewTransform::ViewTransform(jfloat a0, jfloat a1, jfloat a2) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jvalue args[3];
     args[0].f = a0;
     args[1].f = a1;
     args[2].f = a2;
 
     Init(env->NewObjectA(mViewTransformClass, jViewTransform, args), env);
     env->PopLocalFrame(nullptr);
 }
 
 jfloat ViewTransform::getfixedLayerMarginBottom() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jfixedLayerMarginBottom);
 }
 
 void ViewTransform::setfixedLayerMarginBottom(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jfixedLayerMarginBottom, a0);
 }
 
 jfloat ViewTransform::getfixedLayerMarginLeft() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jfixedLayerMarginLeft);
 }
 
 void ViewTransform::setfixedLayerMarginLeft(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jfixedLayerMarginLeft, a0);
 }
 
 jfloat ViewTransform::getfixedLayerMarginRight() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jfixedLayerMarginRight);
 }
 
 void ViewTransform::setfixedLayerMarginRight(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jfixedLayerMarginRight, a0);
 }
 
 jfloat ViewTransform::getfixedLayerMarginTop() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jfixedLayerMarginTop);
 }
 
 void ViewTransform::setfixedLayerMarginTop(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jfixedLayerMarginTop, a0);
 }
 
 jfloat ViewTransform::getoffsetX() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, joffsetX);
 }
 
 void ViewTransform::setoffsetX(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, joffsetX, a0);
 }
 
 jfloat ViewTransform::getoffsetY() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, joffsetY);
 }
 
 void ViewTransform::setoffsetY(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, joffsetY, a0);
 }
 
 jfloat ViewTransform::getscale() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jscale);
 }
 
 void ViewTransform::setscale(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jscale, a0);
 }
 
 jfloat ViewTransform::getx() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jx);
 }
 
 void ViewTransform::setx(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jx, a0);
 }
 
 jfloat ViewTransform::gety() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0.0;
-    }
-
     return env->GetFloatField(wrapped_obj, jy);
 }
 
 void ViewTransform::sety(jfloat a0) {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     env->SetFloatField(wrapped_obj, jy, a0);
 }
 jclass NativeZip::mNativeZipClass = 0;
 jmethodID NativeZip::jCreateInputStream = 0;
 void NativeZip::InitStubs(JNIEnv *jEnv) {
     initInit();
 
     mNativeZipClass = getClassGlobalRef("org/mozilla/gecko/mozglue/NativeZip");
     jCreateInputStream = getMethod("createInputStream", "(Ljava/nio/ByteBuffer;I)Ljava/io/InputStream;");
 }
 
 NativeZip* NativeZip::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     NativeZip* ret = new NativeZip(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 jobject NativeZip::CreateInputStream(jobject a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(2) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallObjectMethod(wrapped_obj, jCreateInputStream, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jobject ret = static_cast<jobject>(env->PopLocalFrame(temp));
     return ret;
 }
 jclass MatrixBlobCursor::mMatrixBlobCursorClass = 0;
 jmethodID MatrixBlobCursor::jMatrixBlobCursor = 0;
 jmethodID MatrixBlobCursor::jMatrixBlobCursor0 = 0;
 jmethodID MatrixBlobCursor::jAddRow = 0;
 jmethodID MatrixBlobCursor::jAddRow1 = 0;
@@ -4214,141 +2283,76 @@ void MatrixBlobCursor::InitStubs(JNIEnv 
     jMatrixBlobCursor0 = getMethod("<init>", "([Ljava/lang/String;I)V");
     jAddRow = getMethod("addRow", "(Ljava/lang/Iterable;)V");
     jAddRow1 = getMethod("addRow", "(Ljava/util/ArrayList;I)V");
     jAddRow2 = getMethod("addRow", "([Ljava/lang/Object;)V");
 }
 
 MatrixBlobCursor* MatrixBlobCursor::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     MatrixBlobCursor* ret = new MatrixBlobCursor(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 MatrixBlobCursor::MatrixBlobCursor(jobjectArray a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     Init(env->NewObject(mMatrixBlobCursorClass, jMatrixBlobCursor, a0), env);
     env->PopLocalFrame(nullptr);
 }
 
 MatrixBlobCursor::MatrixBlobCursor(jobjectArray a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     Init(env->NewObject(mMatrixBlobCursorClass, jMatrixBlobCursor0, a0, a1), env);
     env->PopLocalFrame(nullptr);
 }
 
 void MatrixBlobCursor::AddRow(jobject a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jAddRow, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void MatrixBlobCursor::AddRow(jobject a0, int32_t a1) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jAddRow1, a0, a1);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void MatrixBlobCursor::AddRow(jobjectArray a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallVoidMethod(wrapped_obj, jAddRow2, a0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 jclass SQLiteBridgeException::mSQLiteBridgeExceptionClass = 0;
 jmethodID SQLiteBridgeException::jSQLiteBridgeException = 0;
 jmethodID SQLiteBridgeException::jSQLiteBridgeException0 = 0;
 jfieldID SQLiteBridgeException::jserialVersionUID = 0;
 void SQLiteBridgeException::InitStubs(JNIEnv *jEnv) {
     initInit();
@@ -4356,72 +2360,47 @@ void SQLiteBridgeException::InitStubs(JN
     mSQLiteBridgeExceptionClass = getClassGlobalRef("org/mozilla/gecko/sqlite/SQLiteBridgeException");
     jSQLiteBridgeException = getMethod("<init>", "()V");
     jSQLiteBridgeException0 = getMethod("<init>", "(Ljava/lang/String;)V");
     jserialVersionUID = getStaticField("serialVersionUID", "J");
 }
 
 SQLiteBridgeException* SQLiteBridgeException::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     SQLiteBridgeException* ret = new SQLiteBridgeException(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 SQLiteBridgeException::SQLiteBridgeException() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     Init(env->NewObject(mSQLiteBridgeExceptionClass, jSQLiteBridgeException), env);
     env->PopLocalFrame(nullptr);
 }
 
 SQLiteBridgeException::SQLiteBridgeException(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     Init(env->NewObject(mSQLiteBridgeExceptionClass, jSQLiteBridgeException0, j0), env);
     env->PopLocalFrame(nullptr);
 }
 
 int64_t SQLiteBridgeException::getserialVersionUID() {
     JNIEnv *env = GetJNIForThread();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return 0;
-    }
-
     return env->GetStaticLongField(mSQLiteBridgeExceptionClass, jserialVersionUID);
 }
 jclass Clipboard::mClipboardClass = 0;
 jmethodID Clipboard::jClearText = 0;
 jmethodID Clipboard::jGetClipboardTextWrapper = 0;
 jmethodID Clipboard::jHasText = 0;
 jmethodID Clipboard::jSetClipboardText = 0;
 void Clipboard::InitStubs(JNIEnv *jEnv) {
@@ -4431,136 +2410,70 @@ void Clipboard::InitStubs(JNIEnv *jEnv) 
     jClearText = getStaticMethod("clearText", "()V");
     jGetClipboardTextWrapper = getStaticMethod("getText", "()Ljava/lang/String;");
     jHasText = getStaticMethod("hasText", "()Z");
     jSetClipboardText = getStaticMethod("setText", "(Ljava/lang/CharSequence;)V");
 }
 
 Clipboard* Clipboard::Wrap(jobject obj) {
     JNIEnv *env = GetJNIForThread();
-
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     Clipboard* ret = new Clipboard(obj, env);
     env->DeleteLocalRef(obj);
     return ret;
 }
 
 void Clipboard::ClearText() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     env->CallStaticVoidMethod(mClipboardClass, jClearText);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 jstring Clipboard::GetClipboardTextWrapper() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return nullptr;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return nullptr;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jobject temp = env->CallStaticObjectMethod(mClipboardClass, jGetClipboardTextWrapper);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return nullptr;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     jstring ret = static_cast<jstring>(env->PopLocalFrame(temp));
     return ret;
 }
 
 bool Clipboard::HasText() {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return false;
-    }
-
     if (env->PushLocalFrame(0) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return false;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     bool temp = env->CallStaticBooleanMethod(mClipboardClass, jHasText);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return false;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
     return temp;
 }
 
 void Clipboard::SetClipboardText(const nsAString& a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
-    if (!env) {
-        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
-        return;
-    }
-
     if (env->PushLocalFrame(1) != 0) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        return;
+        AndroidBridge::HandleUncaughtException(env);
+        MOZ_ASSUME_UNREACHABLE("Exception should have caused crash.");
     }
 
     jstring j0 = AndroidBridge::NewJavaString(env, a0);
 
     env->CallStaticVoidMethod(mClipboardClass, jSetClipboardText, j0);
-
-    if (env->ExceptionCheck()) {
-        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
-        env->ExceptionDescribe();
-        env->ExceptionClear();
-        env->PopLocalFrame(nullptr);
-        return;
-    }
-
+    AndroidBridge::HandleUncaughtException(env);
     env->PopLocalFrame(nullptr);
 }
 
 void InitStubs(JNIEnv *jEnv) {
     GeckoAppShell::InitStubs(jEnv);
     JavaDomKeyLocation::InitStubs(jEnv);
     GeckoJavaSampler::InitStubs(jEnv);
     SurfaceBits::InitStubs(jEnv);