Truly @nogc Exceptions?

Atila Neves atila.neves at gmail.com
Thu Sep 20 10:48:35 UTC 2018


On Wednesday, 19 September 2018 at 21:16:00 UTC, Steven 
Schveighoffer wrote:
> Given dip1008, we now can throw exceptions inside @nogc code! 
> This is really cool, and helps make code that uses exceptions 
> or errors @nogc. Except...
>
> The mechanism to report what actually went wrong for an 
> exception is a string passed to the exception during 
> *construction*. Given that you likely want to make such an 
> exception inside a @nogc function, you are limited to passing a 
> compile-time-generated string (either a literal or one 
> generated via CTFE).

<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!


More information about the Digitalmars-d mailing list