forked from jeremy-rifkin/cpptrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.cpp
More file actions
85 lines (77 loc) · 2.67 KB
/
error.cpp
File metadata and controls
85 lines (77 loc) · 2.67 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "utils/error.hpp"
#include <cpptrace/utils.hpp>
#include <exception>
#include "platform/exception_type.hpp"
#include "logging.hpp"
#include "options.hpp"
CPPTRACE_BEGIN_NAMESPACE
namespace detail {
internal_error::internal_error(std::string message) : msg("Cpptrace internal error: " + std::move(message)) {}
constexpr const char* assert_actions[] = {"assertion", "verification", "panic"};
constexpr const char* assert_names[] = {"ASSERT", "VERIFY", "PANIC"};
void assert_fail(
assert_type type,
const char* expression,
const char* signature,
source_location location,
const char* message
) {
const char* action = assert_actions[static_cast<std::underlying_type<assert_type>::type>(type)];
const char* name = assert_names[static_cast<std::underlying_type<assert_type>::type>(type)];
if(message == nullptr) {
throw internal_error(
"Cpptrace {} failed at {}:{}: {}\n"
" {}({});\n",
action, location.file, location.line, signature,
name, expression
);
} else {
throw internal_error(
"Cpptrace {} failed at {}:{}: {}: {}\n"
" {}({});\n",
action, location.file, location.line, signature, message,
name, expression
);
}
}
void panic(
const char* signature,
source_location location,
string_view message
) {
if(message == "") {
throw internal_error(
"Cpptrace panic {}:{}: {}\n",
location.file, location.line, signature
);
} else {
throw internal_error(
"Cpptrace panic {}:{}: {}: {}\n",
location.file, location.line, signature, message
);
}
}
void log_and_maybe_propagate_exception(std::exception_ptr ptr) {
try {
if(ptr) {
std::rethrow_exception(ptr);
}
} catch(const internal_error& e) {
log::error("Unhandled cpptrace internal error: {}", e.what());
} catch(const std::exception& e) {
log::error(
"Unhandled cpptrace internal error of type {}: {}",
cpptrace::demangle(typeid(e).name()),
e.what()
);
} catch(...) {
log::error("Unhandled cpptrace internal error of type {}", detail::exception_type_name());
}
if(!should_absorb_trace_exceptions()) {
if(ptr) {
std::rethrow_exception(ptr);
}
}
}
}
CPPTRACE_END_NAMESPACE