-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminate.cpp
46 lines (38 loc) · 1.02 KB
/
terminate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "terminate.hpp"
#include <cxxabi.h>
#include <boost/exception/diagnostic_information.hpp>
namespace pccl {
namespace error {
namespace detail {
namespace {
void handleTerminate()
{
// std::uncaught_exception doesn't work in this context, so we use a GCC detail
if (abi::__cxa_current_exception_type() != NULL) // we're here because of a C++ exception
{
try
{
throw;
}
catch (boost::exception const& ex)
{
// a boost::exception's what() may not tell the whole story, but here we do
fputs("terminate called after throwing an instance of 'boost::exception'\n", stderr);
fputs(diagnostic_information(ex).c_str(), stderr);
abort();
}
catch (...)
{
}
}
// fall back to the default
__gnu_cxx::__verbose_terminate_handler();
}
} // namespace
TerminateGuard::TerminateGuard()
{
std::set_terminate(handleTerminate);
}
} // namespace detail
} // namespace error
} // namespace pccl