Making Errors errors

sighoya sighoya at gmail.com
Thu Jan 28 19:39:41 UTC 2021


On Thursday, 28 January 2021 at 18:47:27 UTC, Max Haughton wrote:
> I often think of it in the same context as one would in formal 
> verification i.e if this is wrong something catastrophic has 
> happened.

Catastrophic in which sense? To the whole program?

As mentioned by Adam, logical errors rarely justify whole program 
abortion. Downstream code doesn't necessarily require 
computations to succeed on the whole line if it can deal with 
partial results or provide alternate ways to retrieve missing 
information.
> If the problem is exceptional but ultimately recoverable use 
> Exceptions.

Not all Exceptions are recoverable especially if we don't know 
how to deal with. But there may be exemptions silently ignore any 
kind of exception.
The distinction between error and exception is sometimes hard to 
resolve. Is it a usual error if the document doesn't parse or is 
it exceptional?

I think it all depends on subjective assumptions.

> I also feel that, potentially against the grain of Phobos, 
> parsers should not throw - e.g. std.conv probably fails more 
> than it succeeds in many code bases.

This example seems reiterated infinite times and seems true in 
most cases as a parser error is just a value to deal with, we 
don't abort the program immediately, we collect errors in order 
to display them as a sequence of mistakes.

And what to do for cases where aren't interested in any partial 
results, seldom, but such cases would rather be implemented with 
exception handling.




More information about the Digitalmars-d mailing list