File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 1
1
#include < cpptrace/cpptrace.hpp>
2
- #include < cpptrace/version .hpp>
2
+ #include < cpptrace/from_current .hpp>
3
3
4
4
#include < algorithm>
5
5
#include < cctype>
6
6
#include < iostream>
7
7
#include < string>
8
8
9
- void trace () {
9
+ void fail () {
10
+ std::cout << " Throwing an exception from:" << std::endl;
10
11
cpptrace::generate_trace ().print ();
11
- cpptrace::generate_trace ().print_with_snippets ();
12
- throw cpptrace::logic_error (" foobar" );
12
+ throw std::runtime_error (" foobar" );
13
13
}
14
14
15
15
void foo (int n) {
16
16
if (n == 0 ) {
17
- trace ();
17
+ fail ();
18
18
} else {
19
19
foo (n - 1 );
20
20
}
@@ -37,5 +37,10 @@ int main() {
37
37
cpptrace::absorb_trace_exceptions (false );
38
38
cpptrace::use_default_stderr_logger ();
39
39
cpptrace::register_terminate_handler ();
40
- function_one (0 );
40
+ CPPTRACE_TRY {
41
+ function_one (0 );
42
+ } CPPTRACE_CATCH (const std::exception& e) {
43
+ std::cout << " Exception caught: " << e.what () << std::endl;
44
+ cpptrace::from_current_exception ().print ();
45
+ }
41
46
}
You can’t perform that action at this time.
0 commit comments