Skip to content

Commit 56a998c

Browse files
committed
Rework demo binary
1 parent ce63533 commit 56a998c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/demo.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
#include <cpptrace/cpptrace.hpp>
2-
#include <cpptrace/version.hpp>
2+
#include <cpptrace/from_current.hpp>
33

44
#include <algorithm>
55
#include <cctype>
66
#include <iostream>
77
#include <string>
88

9-
void trace() {
10-
cpptrace::generate_trace().print();
11-
cpptrace::generate_trace().print_with_snippets();
12-
throw cpptrace::logic_error("foobar");
9+
void fail() {
10+
throw std::runtime_error("foobar");
1311
}
1412

1513
void foo(int n) {
1614
if(n == 0) {
17-
trace();
15+
fail();
1816
} else {
1917
foo(n - 1);
2018
}
@@ -37,5 +35,10 @@ int main() {
3735
cpptrace::absorb_trace_exceptions(false);
3836
cpptrace::use_default_stderr_logger();
3937
cpptrace::register_terminate_handler();
40-
function_one(0);
38+
CPPTRACE_TRY {
39+
function_one(0);
40+
} CPPTRACE_CATCH(const std::exception& e) {
41+
std::cout << "Exception caught: " << e.what() << std::endl;
42+
cpptrace::from_current_exception().print();
43+
}
4144
}

0 commit comments

Comments
 (0)