nothrow by default

Jonathan M Davis newsgroup.d at
Thu Jan 9 10:32:25 UTC 2020

On Wednesday, January 8, 2020 11:26:41 PM MST Walter Bright via Digitalmars-
d wrote:
> I'm aware that C++ is moving away from exceptions. I've been unhappy with
> exceptions for some time now (DMD doesn't use them for performance
> reasons), and C++ has evidently come to the same conclusion.
> I expect that exceptions will soon become a legacy feature.

I would really hope not. IMHO, they are usually by far the best way to
handle error conditions in a program. Anything else results in you having to
deal with the various possible error conditions when the function returns,
which is _far_ more unwieldy and much more error-prone. It also doesn't work
well with function call chaining.

By using exceptions, you eliminate the need to have error-handling code
everywhere in your program, and unlike stuff like error codes, exceptions
don't get eaten unless the programmer specifically puts in effort to make it

I wouldn't mind us getting rid of Error in favor of killing the program on
the spot, since that's actually better for debugging, and it avoids the
whole argument about whether it's okay to catch Errors. However, Exceptions
are for runtime conditions that aren't necessarily a bug, and they can often
be recovered from. So, being able to throw Exceptions is extremely useful,
and the fact that they don't force you to check for error conditions
everyewhere and instead just handle them in the spots where it makes sense
to handle them makes the code _way_ cleaner.

IMHO, having nothrow be the default would be terrible, and trying to treat
exceptions as a legacy feature would be even worse.

- Jonathan M Davis

More information about the Digitalmars-d mailing list