Why is D unpopular?
Paul Backus
snarwin at gmail.com
Tue May 24 13:48:11 UTC 2022
On Tuesday, 24 May 2022 at 12:51:14 UTC, Loara wrote:
> I think this is better
> ```d
> // debug assertion
> assert(condition);
>
> // release assertion
> if (!condition) throw new AssertError();
> ```
> or also
> ```d
> // debug assertion
> assert(condition);
>
> // release assertion
> if (!condition) throw new MyCustomError("My error message");
> ```
> so when your program fails the final user is aware of what
> went wrong.
I left off messages for the sake of the example, but of course
you should use them in real code.
IMO it is better to use the `assert` keyword than to throw an
`Error`, so that you can use the `-checkaction` switch to choose
what happens at runtime when an assertion fails.
More information about the Digitalmars-d
mailing list