2015-12-04 07:40:12 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <execinfo.h>
|
2016-12-16 20:56:36 +08:00
|
|
|
#include <iostream>
|
2015-12-04 07:40:12 +08:00
|
|
|
|
2018-04-22 14:31:09 +08:00
|
|
|
#include "utils/stacktrace.hpp"
|
|
|
|
|
|
|
|
namespace utils {
|
2015-12-04 07:40:12 +08:00
|
|
|
|
2018-04-22 14:31:09 +08:00
|
|
|
/**
|
|
|
|
* Dump stacktrace to the stream and abort the probram. For more details
|
|
|
|
* about the abort please take a look at
|
|
|
|
* http://en.cppreference.com/w/cpp/utility/program/abort.
|
|
|
|
*/
|
|
|
|
void TerminateHandler(std::ostream &stream) noexcept {
|
2017-02-18 18:54:37 +08:00
|
|
|
if (auto exc = std::current_exception()) {
|
|
|
|
try {
|
|
|
|
std::rethrow_exception(exc);
|
|
|
|
} catch (std::exception &ex) {
|
|
|
|
stream << ex.what() << std::endl << std::endl;
|
2018-04-22 14:31:09 +08:00
|
|
|
utils::Stacktrace stacktrace;
|
|
|
|
stacktrace.dump(stream);
|
2015-12-04 07:40:12 +08:00
|
|
|
}
|
2017-02-18 18:54:37 +08:00
|
|
|
}
|
|
|
|
std::abort();
|
2015-12-14 16:30:32 +08:00
|
|
|
}
|
|
|
|
|
2018-04-22 14:31:09 +08:00
|
|
|
void TerminateHandler() noexcept { TerminateHandler(std::cout); }
|
|
|
|
|
|
|
|
} // namespace utils
|