Search code examples
javaexceptionjava-native-interfacethrow

Undeclared exceptions in JNI


What happens if a JNI dll throws a Java exception, and the java method definition doesn't declare that exception (no throws clause)?

Code:

private native void jniDoSomething(int someValue);

Solution

  • Exception will be thrown anyway. Just have checked this.

    I think such behaviour is because that throws keyword doesn't affect the native code anyway. There is no ability to check if the native code throws the appropriate exception and even in header file there are no mentioning about exceptions.