Logging C++ exceptions inside try/catch block #1231
-
Hello, I'm trying to log an exception from a catch block in our C++ app with sentry native 0.6.6 Currenty the catch block is declared with catch(...) {
/* set bad return code */
} According to docs/AI i've changed it to: catch (std::exception& ex) {
GetApp()->LogException("std::exception", ex.what(), NULL);
/* set bad return code */
} and log the exceptions with: void LogException(const char* szExceptionType, const char* szExceptionValue, const char* szEventMessage)
{
auto event = sentry_value_new_message_event(SENTRY_LEVEL_FATAL, nullptr, szEventMessage);
auto exception = sentry_value_new_exception(szExceptionType, szExceptionValue);
sentry_event_add_exception(event, exception);
sentry_value_set_stacktrace(exception, nullptr, 0);
const auto uuid = sentry_capture_event(event);
} Basically it's working, but I'm not sure if I'm collecting all types of exceptions? for instance the following is not captured as std::execption and falls through the default catch (...) handler: *((unsigned int*)0) = 0xDEAD01; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
In short: no.
Yes, a |
Beta Was this translation helpful? Give feedback.
In short: no.
catch
will only receive C++ exceptions, not allSEH
exceptions. If you want to handleSEH
exceptions, which includes hard faults like memory access errors and C++ exceptions, you need to use the SEH primitives.std::exception
, thus guaranteeing awhat()
interface. In C++, you can throw almost anything (besides incomplete or abstract types), so even if you only consider catching C++ exceptions, you will ignore all that aren't astd::exception
.