Truly @nogc Exceptions?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Sep 20 15:06:06 UTC 2018


On Thu, Sep 20, 2018 at 08:48:13AM -0400, Steven Schveighoffer via Digitalmars-d wrote:
[...]
> But this means you still have to build msg when throwing the
> error/exception. It's not needed until you print it, and there's no
> reason anyway to make it allocate, even with RAII. For some reason D
> forces msg to be built, but it does't e.g. build the entire stack
> trace string before hand, or build the string that shows the exception
> class name or the file/line beforehand.
[...]

IIRC, originally the stacktrace was also built at exception construction
time. But it was causing a major performance hit, so eventually someone
changed the code to construct it lazily (i.e., only when the catcher
actually tries to look it up).

I think it makes sense to also make .msg lazy, if the exception object
is already carrying enough info to build the message when the catcher
asks for it. And if the catcher doesn't ask for it, we saved an extra GC
allocation (which is a plus even if we're not trying to go @nogc).


T

-- 
Computers shouldn't beep through the keyhole.


More information about the Digitalmars-d mailing list