Skip to content

Commit

Permalink
Switch to NativeException for unknown C++ exceptions
Browse files Browse the repository at this point in the history
Error doesn't extend Exception, so it's hard to catch.
  • Loading branch information
kdrag0n committed Aug 22, 2018
1 parent e7a78c4 commit aaf2341
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/main/cpp/java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void rethrow(JNIEnv *env) {
if (clazz)
env->ThrowNew(clazz, e.what());
} catch (const std::exception &e) { // unknown
jclass clazz = env->FindClass("java/lang/Error");
jclass clazz = env->FindClass("com/kdrag0n/tipatch/jni/NativeException");
if (clazz)
env->ThrowNew(clazz, e.what());
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/kdrag0n/tipatch/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.crashlytics.android.Crashlytics
import com.kdrag0n.tipatch.jni.CompressException
import com.kdrag0n.tipatch.jni.Image
import com.kdrag0n.tipatch.jni.ImageException
import com.kdrag0n.tipatch.jni.NativeException
import com.kdrag0n.utils.*
import com.leinardi.android.speeddial.SpeedDialActionItem
import com.leinardi.android.speeddial.SpeedDialView
Expand Down Expand Up @@ -523,7 +524,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh

Crashlytics.logException(e)
}
is Error -> {
is NativeException -> {
if (e.message != null) {
errorDialog(R.string.err_native_unknown(e.message!!), appIssue = true)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kdrag0n.tipatch.jni;

public class NativeException extends RuntimeException {
public NativeException(String text) {
super(text);
}
}

0 comments on commit aaf2341

Please sign in to comment.