r/cpp • • Apr 19 '26

Adding Stack Traces to All C++ Exceptions

https://werwolv.net/posts/cpp_exception_stacktraces/
120 Upvotes

27 comments sorted by

View all comments

Show parent comment

1

u/masscry Apr 19 '26

No, the site just won't load. Funny part - site root loads.

No, as I understand from https://www.boost.org/doc/libs/latest/doc/html/stacktrace/getting_started.html#:~:text=With%20the%20above%20technique%20a,and%20storing%20traces%20in%20exceptions.

It works on any generic exception.

Their approach is similar to nested exceptions, as I presume.

1

u/WerWolv Apr 19 '26

You seem to be right, they inject themselves by overwriting `__cxa_allocate_exception` instead of `__cxa_throw` and going the dynamic linker path I mentioned. Don't think that will work properly though when statically linking but in the general case, their implementation ends up doing pretty much the same thing

https://github.com/boostorg/stacktrace/blob/902537345a72cab9063e5eaa1d7f2e2df5cf1864/src/from_exception.cpp#L233