Skip to content

Commit

Permalink
Improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chippmann committed May 25, 2024
1 parent 295bae9 commit 9c9425d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/jni/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace jni {
String Env::exception_describe() {
#ifdef DEBUG_ENABLED
if (jthrowable e = env->ExceptionOccurred()) {
env->ExceptionClear(); // needs to be cleared now as otherwise it spams errors. We already have a ref to the exception.
env->ExceptionClear(); // needs to be cleared now as otherwise it throws warnings at us in the following two jni calls that we do jni calls with a pending exception
jclass string_writer_class {env->FindClass("java/io/StringWriter")};
jmethodID string_writer_constructor {env->GetMethodID(string_writer_class, "<init>", "()V")};
jobject string_writer {env->NewObject(string_writer_class, string_writer_constructor)};
Expand All @@ -55,6 +55,7 @@ namespace jni {
env->CallVoidMethod(e, print_stack_trace_method, print_writer);

if (exception_check()) {
// if we get here, it means we got an exception while calling `printStackTrace`. Hence, we cannot retrieve the stacktrace. No need to report that to the user. We just return an empty string.
exception_clear();
return {};
}
Expand All @@ -63,6 +64,7 @@ namespace jni {
auto j_stack_trace_string {(jstring) env->CallObjectMethod(string_writer, to_string_method)};

if (exception_check()) {
// if we get here, it means we got an exception while calling `toString`. Hence, we cannot retrieve the stacktrace. No need to report that to the user. We just return an empty string.
exception_clear();
return {};
}
Expand Down

0 comments on commit 9c9425d

Please sign in to comment.