Java Code:
package Package;
public class MyExceptionTester {
private native void compute() throws Exception;
public static void main(String... args) {
try {
MyExceptionTester met = new MyExceptionTester();
met.compute();
} catch(Exception exc) {
System.out.println("From Java :" + exc);
}
}
static {
System.loadLibrary("MyExceptionTester");
}
}
C ++ Code:
#include "iostream"
#include "Package_MyExceptionTester.h"
void Java_Package_MyExceptionTester_compute
(JNIEnv *env, jobject obj) {
jthrowable exc;
try {
jint i = 1/0;
throw "C++ Message : Hey ! Can't Divide By Zero";
} catch(char *str) {
jclass excClass = env->FindClass("java/lang/Exception");
if(excClass == NULL) {
return;
}
env->ThrowNew(excClass,str);
}
}
When I run the java program after turning on the DLL, I get the following message:
Why am I receiving this message? And why I do not see the output, which should be a message printed from a catch java block.
source
share