nothrow by default
Walter Bright
newshound2 at digitalmars.com
Fri Jan 10 01:40:00 UTC 2020
On 1/9/2020 12:39 PM, H. S. Teoh wrote:
> It's not really the exceptions themselves
> that people object to, but the associated implementation issues.
Yes. They're very costly, even in code that never throws.
An approach I've been using with modest success is to design errors entirely out
of the code. For example, in dmd a lot of errors are handled by making a special
AST node for "Error". Subsequent code does nothing with Error nodes.
(Analogously to how floating point code deals with errors, it just sets a NaN
value, which is sticky.)
Another technique is to check for errors in the data first, then the processing
code does not have to check, and cannot fail.
I enjoy trying to set up an API so it cannot fail, then no special code is
needed for errors. Of course, this isn't always possible, and isn't a general
solution. But it's nice when one can make it work.
P.S. I hate throwing constructors, and would force them to be nothrow in D if I
weren't faced with a tsunami of objection to it :-)
More information about the Digitalmars-d
mailing list