Comparing Exceptions and Errors
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Mon Jun 6 07:54:51 UTC 2022
On Monday, 6 June 2022 at 06:56:46 UTC, Ola Fosheim Grøstad wrote:
> On Monday, 6 June 2022 at 06:14:59 UTC, Sebastiaan Koppe wrote:
>> Those are not places where you would put an assert.
>>
>> The only place to put an assert is when *you* know there is no
>> recovery.
>
> No, asserts are orthogonal to recovery. They just specify the
> assumed constraints in the implementation of the algorithm. You
> can view them as comments that can be read by a computer and
> checked for that specific function.
I guess an informal way to express this is:
*Asserts are comments that you would need to make when explaining
why the algorithm works to another person (or to convince
yourself that it works).*
As far as unnecessary asserts, it would be nice to have something
more powerful than static assert, something that could reason
about runtime issues that are simple and issue errors if it could
not establish it. E.g.:
```
int i = 0;
…later…
i++;
…much later…
compiletime_assert(i>0);
```
More information about the Digitalmars-d-learn
mailing list