Error handling meeting summary
Adam D. Ruppe
destructionator at gmail.com
Sun Jul 27 01:05:57 UTC 2025
On Saturday, 26 July 2025 at 21:12:02 UTC, Sebastiaan Koppe wrote:
> Unfortunately the explanation isn't very clear for me. Am I
> correct to think that this will ensure structs in `nothrow`
> functions now get their destructors run on assert / throw Error?
OpenD implemented it back in May:
https://github.com/opendlang/opend/commit/40e11759a82175b2f5edfe855c53a75ce88f176c
So you can always run a test case through the opend compiler to
see what happens. Try this for example:
```
bool destroyed;
struct A {
~this() {
destroyed = true;
}
}
void foo() nothrow {
assert(0);
}
void thing() {
A a;
foo();
}
void main() {
try {
thing();
} catch(Throwable t) {
}
assert(destroyed);
}
```
You'd certainly expect `A`'s dtor to be called at the end of
`thing`, but with upstream, that's not actually the case, since
it thinks the function doesn't do anything that could throw
(`foo` being marked `nothrow` is important to get this result),
and thus never bothers setting up the `finally` block internally
to call that dtor, it just tries to do it at normal function
return.
assert (and range error, or null pointer error - also implemented
in opend a couple months ago, etc) ignore nothrow though, making
it possible to break this assumption. Even if you never *caught*
the `Throwable` like I did here, you still might notice the
missing side effects of the destructor in other ways like if it
did something outside your process.
More information about the Digitalmars-d
mailing list