Throw my own Exception (from JNI code)Tag(s): JNI
The MyOwnException class
public class MyOwnException extends Exception { public MyOwnException(){} public MyOwnException(String txt) { super(txt); } }
JNIEXPORT void JNICALL Java_JavaHowTo_triggerException (JNIEnv *, jobject);
JNIEXPORT void JNICALL Java_JavaHowTo_triggerException (JNIEnv *env, jobject obj) { jclass MyOwnException = env->FindClass("MyOwnException"); env->ThrowNew(MyOwnException,"Exception triggered from JNI routine."); }
class JavaHowTo { public native void triggerException(); static { System.loadLibrary("javahowto"); } }
public class JNIJavaHowTo { public static void main(String[] args) { JavaHowTo jht = new JavaHowTo(); jht.triggerException(); } }