JNI and C++ exceptions

Artem Ananiev artem.ananiev at oracle.com
Fri Sep 27 02:10:05 PDT 2013


here is a short question. In some JDK implementations (e.g. IBM's), JNI 
may throw C++ exceptions. For example, env->NewByteArray() throws 
bad_alloc. Right now in JDK/JavaFX native code we don't protect against 
that. Should we? An anti-pattern that some source scanning tools warn 
about is

<type> obj = new <type>();
if (!obj) {
   // handle that

If SomeJNICall() throws an exception, "obj" will never be deleted. 
Protection against bad_alloc doesn't make much sense, since we're out of 
memory anyway and will unlikely be able to recover, but what about other 



More information about the openjfx-dev mailing list