rendered paste body#include <cxxabi.h>inline const char *demangle_typename(const char *name){ int status = -1; char *dem = abi::__cxa_demangle(name, 0, 0, &status); if(status == 0) return dem; else return 0;}voidreport_exception(const std::exception &ex){ using std::strcmp; using std::strncmp; const char *ex_name = typeid(ex).name(); const char *ex_dem = demangle_typename(ex_name); const char *ex_what = ex.what(); if(ex_dem == 0) ex_dem = ex_name; // some demanglers stick "class" at the beginning of their output, // which looks dumb in this context if(!strncmp(ex_dem, "class ", 6)) ex_dem += 6; // only print what() if it's interesting, i.e. nonempty and // different from the name (mangled or otherwise) of the // exception type. if(ex_what == 0 || ex_what[0] == 0 || !strcmp(ex_what, ex_name)) cerr << ex_dem << endl; else cerr << ex_dem << ": " << ex_what << endl;}