diff --git a/src/stacktraces.cpp b/src/stacktraces.cpp index 31cd312c4c4c..4b8e511585d9 100644 --- a/src/stacktraces.cpp +++ b/src/stacktraces.cpp @@ -686,32 +686,34 @@ crash_info GetCrashInfoFromException(const std::exception_ptr& e) std::string type; std::string what; + auto getExceptionType = [&]() -> std::string { + auto type = abi::__cxa_current_exception_type(); + if (type && (strlen(type->name()) > 0)) { + return DemangleSymbol(type->name()); + } + return ""; + }; + try { // rethrow and catch the exception as there is no other way to reliably cast to the real type (not possible with RTTI) std::rethrow_exception(e); } catch (const std::exception& e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (const std::string& e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (const char* e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (int e) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = GetExceptionWhat(e); } catch (...) { - type = abi::__cxa_current_exception_type()->name(); + type = getExceptionType(); what = ""; } - if (type.empty()) { - type = ""; - } else { - type = DemangleSymbol(type); - } - ci.crashDescription += strprintf("type=%s, what=\"%s\"", type, what); auto stackframes = GetExceptionStacktrace(e);