Skip to content

Logging C++ exceptions inside try/catch block #1229

@maxp1256

Description

@maxp1256

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions