[OT] OT: Null checks.
kdevel
kdevel at vogtner.de
Tue May 6 18:25:00 UTC 2025
On Tuesday, 6 May 2025 at 06:11:29 UTC, Walter Bright wrote:
> D is set up so if you throw an `Exception`, then destructors
> will run as the stack unwinds. But if you throw an `Error`, you
> can catch it but the destructors don't run.
I cannot confirm this:
```
$ cat errors.d
import std;
struct S {
this (int) { writeln (__PRETTY_FUNCTION__); }
~this () { writeln (__PRETTY_FUNCTION__); }
}
int baz ()
{
auto s = S (2);
throw new Error ("ex");
return 0;
}
int main ()
{
try return baz;
catch (Throwable t)
stderr.writeln (t.msg);
return 1;
}
$ dmd -O errors.d
$ ./errors
S errors.S.this(int __param_0) ref
void errors.S.~this()
ex
```
More information about the Digitalmars-d
mailing list