I have a Java library which run a series of tasks. And I registered a default uncaught exception handler using:
Thread.setDefaultUncaughtExceptionHandler(new JavaUncaughtExceptionHandler());
The UncaughtExceptionHandler implements UncaughtExceptionHandler
and only log the error information in STDERR
.
My Java library is called through JNI from C++ code, and the JNI is calling it with ExceptionCheck()
and log the error as FATAL in C++.
The problem is:
In the runtime, when there's a RuntimeException
(or any other uncaught exception) happens in my Java code, the error got captured in C++ instead of my JavaUncaughtExceptionHandler
registered as thread default uncaught exception handler.
- Is that the excepted behaviour?
- When will the
DefaultUncaughtExceptionHandler
actually got called? I know before thread got shutdown, but when specifically in JNI case. Is that called before return to C++ or after C++ code finished as well). I think it's related to the thread management in JNI, please share any related information as well. - Is there anyway I can catch all the exceptions in my Java code (other alternative way except put a
try
/catch
blocks)
Thanks so much.