C++ Logo


Advanced search

Re: Are Exceptions deeply flawed?

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 05 Aug 2019 22:16:29 -0700
On Monday, 5 August 2019 01:45:13 PDT Dmitry via Std-Discussion wrote:
> I wrote a post -
> https://www.reddit.com/r/cpp/comments/cliw5j/should_not_exceptions_be_finall
> y_deprecated/ in the hope to get answers to at least 3 questions at the top
> because the are very practical and I have to deal with them every day.
> I would be grateful to here what you think.

Disclaimer: I don't use exceptions in my code, my libraries never throw, I
never test exception-safety.

But I think you've fallen into the fallacy of focusing on the mechanism
instead of the objective. The exception is the means to transport an error
condition in a type-safe manner and unwind the stack. The same can be
accomplished with error conditions and returns and in fact does happen: I can
make your situations more concrete based on what I did at work today: I had a
function f() that opened a temporary file and returned a file descriptor, but
instead of opening a real file, now it opens a Linux memfd. That means EACCESS
can no longer happen. At the same time, we can get an ENOSYS if you're running
on Linux less than 3.17.

How does the caller's code get updated to handle the new condition and stop
handling the now never-impossible one?

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2019-08-06 00:18:31