forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterminate_handler.cc
39 lines (31 loc) · 1.1 KB
/
terminate_handler.cc
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
#include "source/exe/terminate_handler.h"
#include <cstdlib>
#include "envoy/common/exception.h"
#include "source/common/common/logger.h"
#include "source/server/backtrace.h"
#include "absl/strings/str_format.h"
namespace Envoy {
std::terminate_handler TerminateHandler::logOnTerminate() const {
return std::set_terminate([]() {
logException(std::current_exception());
BACKTRACE_LOG();
std::abort();
});
}
void TerminateHandler::logException(const std::exception_ptr current_exception) {
if (current_exception != nullptr) {
try {
std::rethrow_exception(current_exception);
} catch (const EnvoyException& e) {
ENVOY_LOG(critical, "std::terminate called! Uncaught EnvoyException '{}', see trace.",
e.what());
} catch (const std::exception& e) {
ENVOY_LOG(critical, "std::terminate called! Uncaught exception '{}', see trace.", e.what());
} catch (...) {
ENVOY_LOG(critical, "std::terminate called! Uncaught unknown exception, see trace.");
}
} else {
ENVOY_LOG(critical, "std::terminate called! See trace.");
}
}
} // namespace Envoy