Created
March 8, 2024 05:53
-
-
Save jhurliman/ba88bf412e126e3ff65184fa7aabaf98 to your computer and use it in GitHub Desktop.
Better C++ exception printing for Catch2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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