| 320 | |
| 321 | |
| 322 | void Backtrace::writeCrashLog(ostream &out) { |
| 323 | Backtrace bt(4); |
| 324 | auto xp = current_exception(); |
| 325 | if (xp) { |
| 326 | out << "Uncaught exception:\n\t"; |
| 327 | try { |
| 328 | rethrow_exception(xp); |
| 329 | } catch(const exception& x) { |
| 330 | const char *name = typeid(x).name(); |
| 331 | char *unmangled = unmangle(name); |
| 332 | out << unmangled << ": " << x.what() << "\n"; |
| 333 | if (unmangled != name) |
| 334 | free(unmangled); |
| 335 | } catch (...) { |
| 336 | out << "unknown exception type\n"; |
| 337 | } |
| 338 | } |
| 339 | out << "Backtrace:"; |
| 340 | bt.writeTo(out); |
| 341 | } |
| 342 | |
| 343 | |
| 344 | void Backtrace::installTerminateHandler(function<void(const string&)> logger) { |