-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_trace.hpp
39 lines (31 loc) · 1023 Bytes
/
stack_trace.hpp
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
#pragma once
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <string>
#include <boost/stacktrace.hpp>
#include <boost/exception/all.hpp>
namespace Crashser
{
template<typename Exception>
void throwWithStackTrace(const Exception& e) {
using traced = boost::error_info<struct tag_stacktrace, boost::stacktrace::stacktrace>;
auto temp = boost::enable_error_info(e) << traced(boost::stacktrace::stacktrace());
throw temp;
}
template<typename Exception>
std::string getStackTrace(const Exception& e)
{
using traced = boost::error_info<struct tag_stacktrace, boost::stacktrace::stacktrace>;
const boost::stacktrace::stacktrace* stack_trace = boost::get_error_info<traced>(e);
if (stack_trace) {
return to_string(*stack_trace);
} else {
return boost::diagnostic_information(e);
}
}
inline std::string getStackTrace()
{
return to_string(boost::stacktrace::stacktrace());
}
}