Mercurial > hg > orthanc-java
comparison Plugin/JavaEnvironment.cpp @ 27:4a750ca9461e
logging message associated with an exception
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jun 2024 19:14:51 +0200 |
parents | 1c407ba1d311 |
children | 10406d66d1c6 |
comparison
equal
deleted
inserted
replaced
26:a4326b544c51 | 27:4a750ca9461e |
---|---|
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 **/ | 22 **/ |
23 | 23 |
24 | 24 |
25 #include "JavaEnvironment.h" | 25 #include "JavaEnvironment.h" |
26 #include "JavaString.h" | |
26 | 27 |
27 #include <cassert> | 28 #include <cassert> |
28 #include <stdexcept> | 29 #include <stdexcept> |
29 | 30 |
30 extern OrthancPluginContext* context_; | 31 extern OrthancPluginContext* context_; |
96 | 97 |
97 void JavaEnvironment::CheckException() | 98 void JavaEnvironment::CheckException() |
98 { | 99 { |
99 if (env_->ExceptionCheck() == JNI_TRUE) | 100 if (env_->ExceptionCheck() == JNI_TRUE) |
100 { | 101 { |
102 jthrowable e = env_->ExceptionOccurred(); | |
101 env_->ExceptionClear(); | 103 env_->ExceptionClear(); |
104 | |
105 jclass clazz = env_->GetObjectClass(e); | |
106 if (clazz != NULL) | |
107 { | |
108 jmethodID getMessage = env_->GetMethodID(clazz, "getMessage", "()Ljava/lang/String;"); | |
109 if (getMessage != NULL) | |
110 { | |
111 JavaString message(env_, (jstring) env_->CallObjectMethod(e, getMessage)); | |
112 throw std::runtime_error("An exception has occurred in Java: " + std::string(message.GetValue())); | |
113 } | |
114 } | |
115 | |
102 throw std::runtime_error("An exception has occurred in Java"); | 116 throw std::runtime_error("An exception has occurred in Java"); |
103 } | 117 } |
104 } | 118 } |
105 | 119 |
106 | 120 |