Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created March 8, 2024 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhurliman/ba88bf412e126e3ff65184fa7aabaf98 to your computer and use it in GitHub Desktop.
Save jhurliman/ba88bf412e126e3ff65184fa7aabaf98 to your computer and use it in GitHub Desktop.
Better C++ exception printing for Catch2
#include <cxxabi.h>
#include <typeinfo>
CATCH_TRANSLATE_EXCEPTION(const std::exception& e) {
std::string s;
int status;
const char* name = typeid(e).name();
char* realname = abi::__cxa_demangle(name, 0, 0, &status);
if (realname) {
s.append(realname);
} else {
s.append(name);
}
s.append(": ");
s.append(e.what());
free(realname);
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment