Postmortem: Template unittests are bad & you shouldn't catch Error
Timon Gehr
timon.gehr at gmx.ch
Thu Oct 22 22:45:52 UTC 2020
On 22.10.20 18:28, Timon Gehr wrote:
>
> Also, code that "relies on such unwinding" can be annotated @safe and
> the compiler won't complain.
Actually, it will complain. Sorry for the noise, should have
double-checked before sending the post.
However, in contracts do rely on catching AssertError, and they are
allowed in @safe code:
---
void bar()@safe{
import std.stdio;
writeln("throwing an AssertError");
assert(0);
}
void main()@safe{
class C{
void foo()@safe in{ bar(); }do{}
}
class D:C{
override void foo()@safe in{}do{}
}
auto d=new D;
d.foo();
}
---
Prints:
throwing an AssertError
The program does not abort.
If catching an AssertError is UB, why does the language do it in @safe code?
More information about the Digitalmars-d
mailing list