jeremy-rifkin / cpptrace

Simple, portable, and self-contained stacktrace library for C++11 and newer
MIT License
621 stars 64 forks source link

How can I define a custom exception extends cpptrace::exception support with/without trace? #108

Closed vipcxj closed 5 months ago

vipcxj commented 5 months ago

I want to create a custom exception suport with/without trace which decide by user. Maybe I can pass an empty raw_trace to do this. But I don't know how to construct an empty raw_trace and make sure that I don't call the relevant methods of raw_trace afterward, resulting in bugs

jeremy-rifkin commented 5 months ago

Hi, a raw_trace is just a struct with a vector so you can create an empty raw trace with cpptrace::raw_trace{}. It's safe to call any member function on this empty raw trace. By default cpptrace::raw_trace{}.resolve().print() will just print

Stack trace (most recent call first):
<empty trace>
jeremy-rifkin commented 5 months ago

I'll close for now, please let me know if there's anything else I can help with or if you think the current system could be improved!