Returns a basic_stacktrace object containing a stacktrace captured at the point where the currently handled exception was thrown by its initial throw-expression (i.e. not a rethrow), or an empty basic_stacktrace object if: - the `boost_stacktrace_from_exception` library is not linked to the current binary, or - the initialization of stacktrace failed, or - stacktrace captures are not enabled for
| 392 | /// |
| 393 | /// Implements https://wg21.link/p2370r1 |
| 394 | static basic_stacktrace<Allocator> from_current_exception(const allocator_type& alloc = allocator_type()) noexcept { |
| 395 | // Matches the constant from implementation |
| 396 | constexpr std::size_t kStacktraceDumpSize = 4096; |
| 397 | |
| 398 | const char* trace = nullptr; |
| 399 | #if defined(__GNUC__) && defined(__ELF__) |
| 400 | if (impl::current_exception_stacktrace) { |
| 401 | trace = impl::current_exception_stacktrace(); |
| 402 | } |
| 403 | #elif defined(BOOST_MSVC) |
| 404 | trace = boost_stacktrace_impl_current_exception_stacktrace(); |
| 405 | #endif |
| 406 | |
| 407 | if (trace) { |
| 408 | try { |
| 409 | return basic_stacktrace<Allocator>::from_dump(trace, kStacktraceDumpSize, alloc); |
| 410 | } catch (const std::exception&) { |
| 411 | // ignore |
| 412 | } |
| 413 | } |
| 414 | return basic_stacktrace<Allocator>{0, 0, alloc}; |
| 415 | } |
| 416 | }; |
| 417 | |
| 418 | /// @brief Compares stacktraces for less, order is platform dependent. |