# HG changeset patch # User Sebastien Jodogne # Date 1718126091 -7200 # Node ID 4a750ca9461e84ef521939273b9a7bbaaa3f9d0c # Parent a4326b544c5171047368853a01d2f0ced7ac96a6 logging message associated with an exception diff -r a4326b544c51 -r 4a750ca9461e Plugin/JavaEnvironment.cpp --- a/Plugin/JavaEnvironment.cpp Sat Apr 06 17:24:15 2024 +0200 +++ b/Plugin/JavaEnvironment.cpp Tue Jun 11 19:14:51 2024 +0200 @@ -23,6 +23,7 @@ #include "JavaEnvironment.h" +#include "JavaString.h" #include #include @@ -98,7 +99,20 @@ { if (env_->ExceptionCheck() == JNI_TRUE) { + jthrowable e = env_->ExceptionOccurred(); env_->ExceptionClear(); + + jclass clazz = env_->GetObjectClass(e); + if (clazz != NULL) + { + jmethodID getMessage = env_->GetMethodID(clazz, "getMessage", "()Ljava/lang/String;"); + if (getMessage != NULL) + { + JavaString message(env_, (jstring) env_->CallObjectMethod(e, getMessage)); + throw std::runtime_error("An exception has occurred in Java: " + std::string(message.GetValue())); + } + } + throw std::runtime_error("An exception has occurred in Java"); } }