From d5a9092da0329865350a6b389fa2e748a5b24998 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 21 Oct 2024 22:14:16 -0700 Subject: [PATCH] Fallback to toString when getErrorDescription fails Summary: Fallback to the previous toString call when `getErrorDescription` fails (for unknown reasons). Reviewed By: mhorowitz Differential Revision: D64693634 fbshipit-source-id: e9fe72663717b3808885457c16577254b8bd995c --- cxx/fbjni/detail/Exceptions.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cxx/fbjni/detail/Exceptions.cpp b/cxx/fbjni/detail/Exceptions.cpp index db65d9e..77654c4 100644 --- a/cxx/fbjni/detail/Exceptions.cpp +++ b/cxx/fbjni/detail/Exceptions.cpp @@ -425,8 +425,8 @@ local_ref JniException::getThrowable() const noexcept { // TODO 6900503: consider making this thread-safe. void JniException::populateWhat() const noexcept { + ThreadScope ts; try { - ThreadScope ts; static auto exceptionHelperClass = findClassStatic("com/facebook/jni/ExceptionHelper"); static auto getErrorDescriptionMethod = @@ -436,7 +436,12 @@ void JniException::populateWhat() const noexcept { ->toStdString(); isMessageExtracted_ = true; } catch (...) { - what_ = kExceptionMessageFailure; + try { + what_ = throwable_->toString(); + isMessageExtracted_ = true; + } catch (...) { + what_ = kExceptionMessageFailure; + } } }