Print message when throwing new exception with pending exception.
Useful to see what the new exception is.
Bug: 12957138
Change-Id: I751b3a9b0b5d57d72f15d3ed7fa746a1991b181c
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 8b93b91..4fe9169 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -1005,6 +1005,15 @@
}
}
+void Thread::AssertNoPendingExceptionForNewException(const char* msg) const {
+ if (UNLIKELY(IsExceptionPending())) {
+ ScopedObjectAccess soa(Thread::Current());
+ mirror::Throwable* exception = GetException(nullptr);
+ LOG(FATAL) << "Throwing new exception " << msg << " with unexpected pending exception: "
+ << exception->Dump();
+ }
+}
+
static void MonitorExitVisitor(mirror::Object** object, void* arg, uint32_t /*thread_id*/,
RootType /*root_type*/)
NO_THREAD_SAFETY_ANALYSIS {
@@ -1507,7 +1516,8 @@
void Thread::ThrowNewException(const ThrowLocation& throw_location, const char* exception_class_descriptor,
const char* msg) {
- AssertNoPendingException(); // Callers should either clear or call ThrowNewWrappedException.
+ // Callers should either clear or call ThrowNewWrappedException.
+ AssertNoPendingExceptionForNewException(msg);
ThrowNewWrappedException(throw_location, exception_class_descriptor, msg);
}