Truly @nogc Exceptions?
Atila Neves
atila.neves at gmail.com
Thu Sep 20 14:12:39 UTC 2018
On Thursday, 20 September 2018 at 12:48:13 UTC, Steven
Schveighoffer wrote:
> On 9/20/18 6:48 AM, Atila Neves wrote:
>> On Wednesday, 19 September 2018 at 21:16:00 UTC, Steven
>> Schveighoffer wrote:
>>> [...]
>>
>> <snip>
>>
>> I expressed my concern for DIP1008 and the `msg` field when it
>> was first announced. I think the fix is easy and a one line
>> change to dmd. I also expressed this on that thread but was
>> apparently ignored. What's the fix? Have the compiler insert a
>> call to the exception's destructor at the end of the
>> `catch(scope Exception)` block. That's it. The `msg` field is
>> just a slice, point it to RAII managed memory and you're good
>> to go.
>>
>> Give me deterministic destruction of exceptions caught by
>> scope when using dip1008 and I'll give you @nogc exception
>> throwing immediately. I've even already written the code!
>
> I thought it already did that? How is the exception destroyed
> when dip1008 is enabled?
I've had a 2 week holiday since I was working on this so I don't
quite remember. I'll try and find out the specifics for you later.
What I do remember is that the destructor didn't get called.
> 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.
Maybe, but it's a lot easier to just allocate and have the
destructor take care of it.
> 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.
Good points.
More information about the Digitalmars-d
mailing list