Skip to content

Commit 3abeea4

Browse files
committed
Rework demo binary
1 parent ce63533 commit 3abeea4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

test/demo.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
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() {
9+
void fail() {
10+
std::cout << "Throwing an exception from:" << std::endl;
1011
cpptrace::generate_trace().print();
11-
cpptrace::generate_trace().print_with_snippets();
12-
throw cpptrace::logic_error("foobar");
12+
throw std::runtime_error("foobar");
1313
}
1414

1515
void foo(int n) {
1616
if(n == 0) {
17-
trace();
17+
fail();
1818
} else {
1919
foo(n - 1);
2020
}
@@ -37,5 +37,10 @@ int main() {
3737
cpptrace::absorb_trace_exceptions(false);
3838
cpptrace::use_default_stderr_logger();
3939
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+
}
4146
}

0 commit comments

Comments
 (0)