11 #ifndef __EXCEPTION_H__
12 #define __EXCEPTION_H__
23 : std::runtime_error((message.insert(0,
"[ERROR] "), std::move(message)))
30 :
cgrame_error((message.insert(0,
"[MAPPER] "), std::move(message)))
37 :
cgrame_error((message.insert(0,
"[VISUAL] "), std::move(message)))
44 :
cgrame_error((message.insert(0,
"[ADL] "), std::move(message)))
51 :
cgrame_error((message.insert(0,
"[MODEL] "), std::move(message)))
65 template<
typename EXCEPTION,
typename FUNC>
67 std::ostringstream os;
69 throw EXCEPTION(os.str());
84 template<
typename T,
typename FUNC>
86 std::ostringstream os;
96 std::ostringstream stream;
110 std::rethrow_exception(eptr);
112 }
catch (
const std::exception& e) {
114 os <<
"std::exception thrown when " << action_name <<
": .what() = " << e.what() << std::endl;
116 std::fprintf(stderr,
"exception encountered when handling std::exception when %s", action_name);
121 os <<
"unknown exception thrown when " << action_name << std::endl;
123 std::fprintf(stderr,
"exception encountered when handling unknown exception when %s", action_name);
135 std::stringstream msg;
137 << line_prefix <<
'\n'
138 << line_prefix <<
' ' << message <<
". Exception chain:\n"
143 msg << line_prefix;
for (
int i = 0; i < level + 2; ++i) msg <<
' ';
147 std::rethrow_exception(eptr);
148 }
catch (
const std::exception& e) {
149 msg <<
".what(): " << e.what() <<
'\n';
151 msg <<
"Unknown exception\n";
156 std::rethrow_exception(eptr);
157 }
catch (
const std::nested_exception& as_ne) {
159 as_ne.rethrow_nested();
161 eptr = std::current_exception();
172 fprintf(stdout,
"[stdout]\n%s\n", msg.str().c_str());
174 fprintf(stderr,
"[stderr]\n%s\n", msg.str().c_str());