Error handling meeting summary
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sat Jul 26 19:55:17 UTC 2025
On 26/07/2025 12:03 PM, Steven Schveighoffer wrote:
> On Friday, 25 July 2025 at 16:58:43 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> Hello all!
>>
>> We've had a meeting on how error handling should work in D.
>>
>> Approved work:
>>
>> - Finalisers are brought back to the baseline behaviour. They will not
>> be rewritten to sequences in the frontend.
>
> Can you explain this? The link isn't very explanatory for those who
> don't understand the DMD codebase.
>
> -Steve
Yeah sure.
Right now final statements are different behavior based upon if the
trybody scope could throw an ``Exception`` class.
If they do not throw an ``Exception``, it will rewrite it so that it is
a sequence: ``trybody; finalbody;``
Final statements are used for a lot of things, running destructors of
structs, or ``scope(exit)`` for instance.
That's a problem, its half way between two cleanup strategies. Never run
cleanup on throwing of an ``Error`` or always cleaning up when ``Error``
is thrown.
An example of this behavior is the following code, where the destructor
will run:
```d
void do1() {
assert(0);
}
void main()
{
static struct S
{
~this()
{
import std.stdio;
writeln("destructor ran!");
}
}
S s;
do1;
}
```
Bringing this back to baseline behavior of no rewrites, means that we
can pick which strategy people want to use.
More information about the Digitalmars-d
mailing list