C++ Logo

std-proposals

Advanced search

Re: Stacktrace from exception

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Thu, 29 Apr 2021 12:08:14 +0100
On Thu, 29 Apr 2021 at 11:41, Gašper Ažman <gasper.azman_at_[hidden]> wrote:

> As others have said - exceptions are definitely not for situations where
> you are signaling a bug. That's what contracts are for. Never mind we don't
> have them, but exceptions are definitely not for signaling bugs.
> std::logic_error should be deprecated and removed once contracts land (yes,
> I know it's not gonna happen, but one can dream).
>
> From the contract violation handler, you will definitely be able to both
> gracefully exit (save the document and terminate, for instance), as well as
> get the current stack trace.
>
> Exceptions don't give you anything that makes dealing with bugs easier. In
> other words, exceptions *are* for control flow - exceptional control flow.
> Not bugs.
>

I agree, that's great if we manage to get to a place where (a) exceptions
are suitable for control flow, and (b) contracts are available to signal
bugs. But currently the situation in C++ is that exceptions are expensive
to use, so they are unsuitable for control flow, but they can be and are
used to signal bugs. Even if both contracts and P0709-style exceptions land
in C++23, there will be 25 years' worth of code written in what was at the
time Standard C++ that uses exceptions to signal bugs. The facility
proposed here would be invaluable dealing with such code.

Received on 2021-04-29 06:08:26