24#define mthrow(arg) (throw mexception(arg, true, __FILE__, __LINE__))
27#define mthrow1(arg) (throw mexception(arg, false, __FILE__, __LINE__))
30#define mthrow2(arg) (throw mexception(arg, false, "", 0))
35 mexception(
const std::string &arg,
bool stack_trace,
const char *
file,
int line) :
36 std::runtime_error(arg) {
37 std::stringstream trace_buf;
39 trace_buf <<
file <<
":" << line <<
": " << arg;
45 trace_buf << std::endl <<
"Stack trace:" << std::endl;
48 int n = backtrace(callstack,
sizeof(callstack) /
sizeof(callstack[0]));
49 char **symbols = backtrace_symbols(callstack,
n);
50 for (
int i = 1;
i <
n;
i++) {
52 if (dladdr(callstack[
i], &
info)) {
53 char *demangled =
nullptr;
55 demangled = abi::__cxa_demangle(
info.dli_sname,
nullptr, 0, &
status);
56 snprintf(buf,
sizeof(buf),
"%-3d 0x%018lX %s + %zd\n",
57 i, (
long unsigned int) callstack[
i],
59 (
char *) callstack[
i] - (
char *)
info.dli_saddr);
62 snprintf(buf,
sizeof(buf),
"%-3d 0x%018lX\n",
63 i, (
long unsigned int) callstack[
i]);
70 msg = trace_buf.str();
75 const char *
what()
const throw() {
87static_assert(std::is_nothrow_copy_constructible<mexception>::value,
88 "mexception must be nothrow copy constructible");
const char * what() const
mexception(const std::string &arg, bool stack_trace, const char *file, int line)
friend std::ostream & operator<<(std::ostream &output, mexception &m)
mexception(const mexception &ex) noexcept
static void output(code_int code)