Search code examples
javac++exceptionjvmjava-native-interface

Does jni::ExceptionDescribe implicitily clear the exception trace of the JNI environment object?


I tried to implement some kind of exception handling

At first i called jni::ExceptionDescribe()

after that i used the implementation of

How to obtain a description of a Java exception in C++ when using JNI?

which i just named for simplicity printStackTrace()and which completely works fine .

My problem is that i can not use them in combination like this.

some c++ code

void aCppMethod() {

     jni::ExceptionDescribe(); //Works
     printStackTrace(); // No stack trace avaiable because JNI Env does not hold any exception

}

but

void aCppMethod() {
  // jni::ExceptionDescribe(); //commented out
  printStackTrace(); // Works, where printStackeTrace just prints the Exception into a single log file

    }

My question is does jni::ExceptionDescribe() implicitely deletes the exception from the Java Environment object and is there a simple possibility to use both function in a simple sequence.

Or much more better. Is there any hook, or overriding mechanism to enhance or change the behaviour of jni::ExceptionDescribe()

The reason i need both behaviours, is because i want to use the appropriate C++ Code as simple Windows Executable and also as a DLL.


Solution

  • Apparently described behaviour was reported 18 years ago on Windows, please check here. Then with explanation "it looks like addressed" bug was closed during 2002. What you are describing looks very similar to mentioned bug.