boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
422 stars 69 forks source link

Implement stacktrace from current exception for MSVC #159

Closed huangqinjin closed 4 months ago

huangqinjin commented 5 months ago

Original stacktrace from std::exception_ptr is not possible currently. std::current_exception() makes a copy of current exception object into returned std::exception_ptr. So the tracking of the original exception object and its stacktrace are lost.

Support for nested exceptions ~is not much meaningful IMO, it~ complicates the implementation (see the last commit). Without nested exceptions support, one can always get stacktrace from current exception immediately after entering catch block, but it loses the original stacktrace for rethrow_after_other_exception case.

The exception object is destroyed by __DestructExceptionObject exported from vcruntime.dll, there is no simple way to cleanup stored traces in time unless override __DestructExceptionObject.

coveralls commented 4 months ago

Coverage Status

coverage: 86.308%. remained the same when pulling f76e128ab300abdff687590a075aac9e21844247 on huangqinjin:msvc-stacktrace-from-current-exception into 351b03d5220510a1b6738cc378659b6d85c8a4da on boostorg:develop.

apolukhin commented 4 months ago

Many thanks for the great PR!