2015-12-04 07:40:12 +08:00
|
|
|
#pragma once
|
|
|
|
|
2015-12-14 16:30:32 +08:00
|
|
|
#include "utils/auto_scope.hpp"
|
2016-12-16 20:56:36 +08:00
|
|
|
#include "utils/stacktrace.hpp"
|
2015-12-14 16:30:32 +08:00
|
|
|
|
2015-12-04 07:40:12 +08:00
|
|
|
#include <execinfo.h>
|
2016-12-16 20:56:36 +08:00
|
|
|
#include <iostream>
|
2015-12-04 07:40:12 +08:00
|
|
|
|
|
|
|
// TODO: log to local file or remote database
|
2016-12-16 20:56:36 +08:00
|
|
|
void stacktrace(std::ostream& stream) noexcept {
|
|
|
|
Stacktrace stacktrace;
|
2016-12-16 22:49:20 +08:00
|
|
|
stacktrace.dump(stream);
|
2015-12-04 07:40:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: log to local file or remote database
|
2016-12-16 20:56:36 +08:00
|
|
|
void terminate_handler(std::ostream& stream) noexcept {
|
|
|
|
if (auto exc = std::current_exception()) {
|
|
|
|
try {
|
|
|
|
std::rethrow_exception(exc);
|
|
|
|
} catch (std::exception& ex) {
|
|
|
|
stream << ex.what() << std::endl << std::endl;
|
|
|
|
stacktrace(stream);
|
2015-12-04 07:40:12 +08:00
|
|
|
}
|
2016-12-16 20:56:36 +08:00
|
|
|
}
|
|
|
|
std::abort();
|
2015-12-14 16:30:32 +08:00
|
|
|
}
|
|
|
|
|
2016-12-16 20:56:36 +08:00
|
|
|
void terminate_handler() noexcept { terminate_handler(std::cout); }
|