Subject: Re: [std-proposals] Adding stacktrace to std::exception
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2020-11-12 10:02:53
On 11/12/20 6:27 PM, Antony Polukhin via Std-Proposals wrote:
> ÑÑ, 12 Ð½Ð¾ÑÐ±. 2020 Ð³. Ð² 17:39, Christof Meerwald via Std-Proposals
>> On Thu, Nov 12, 2020 at 05:14:52PM +0300, Antony Polukhin via Std-Proposals wrote:
>>> ÑÑ, 11 Ð½Ð¾ÑÐ±. 2020 Ð³. Ð² 20:32, Kilian Henneberger via Std-Proposals
>>>> Hello everyone,
>>>> if I am informed correctly, P0881 (https://wg21.link/P0881) has been
>>>> approved for C++23.
>>>> And I assume this is no new idea (also not to C++), but what do you
>>>> think about adding a stacktrace to std::exception?
>>> This is a very good idea that was not discussed, because this seemed
>>> to be an ABI breaking change.
>> Wouldn't that add significant run-time overhead to every throw
> It depends. Some implementations may store the stacktrace entry on
> unwinding. That's literally a 1 cmov instruction due to the fact that
> the implementation already works with the frame pointer
I'm not sure I understand how that would work. Saving a frame pointer is
not enough since stack frames would be naturally destroyed during
unwinding, so at the point where you catch the exception and about to
get the stacktrace the pointer is useless.
Generating stacktraces at compile time also doesn't seem feasible, since
there may be a lot ways the control could get to a particular throw
statement. So it seems some state capturing should happen at run time,
and that work could have a linear complexity.
>> This really needs to be opt-in, but in that case you can just get the
>> stacktrace in your exception's constructor?
> You can use std::stracktrace in your exceptions with C++23. However,
> getting stacktraces for any exception out-of-the-box is a tempting
> feature, especially for big codebases with legacy parts.
Legacy code bases won't be using new features, like std::stracktrace.
I would rather prefer to have a standard way to attach arbitrary
information to exceptions, like Boost.Exception.
STD-PROPOSALS list run by email@example.com
Standard Proposals Archives on Google Groups