diff --git a/src/java/Exception.cxx b/src/java/Exception.cxx index 1bd4c6533..118353ca8 100644 --- a/src/java/Exception.cxx +++ b/src/java/Exception.cxx @@ -39,12 +39,10 @@ Java::Exception::Exception(JNIEnv *env, jthrowable e) noexcept void Java::RethrowException(JNIEnv *env) { - jthrowable exception = env->ExceptionOccurred(); - if (exception == nullptr) + LocalRef exception{env, env->ExceptionOccurred()}; + if (!exception) return; - LocalRef ref(env, exception); - env->ExceptionClear(); throw Exception(env, exception); }