DIP33: A standard exception hierarchy

Walter Bright newshound2 at digitalmars.com
Wed Apr 3 02:20:03 PDT 2013


On 4/2/2013 1:00 PM, Lars T. Kyllingstad wrote:
> I definitely don't think we need an IllegalArgumentException. IMO, passing
> illegal arguments is 1) a simple programming error, in which case it should be
> an Error, or 2) something the programmer can not avoid, in which case it
> requires a better description of why things went wrong than just "illegal
> argument".  "File not found", for example.
>
> I didn't really consider contracts when I wrote the DIP, and of course there
> will always be the problem of "should this be a contract or a normal input
> check?"  The problem with contracts, though, is that they go away in release
> mode, which is certainly not safe if that is your error handling mechanism.

A bit of philosophy here:

Contracts are not there to validate user input. They are only there to check for 
logic bugs in the program itself.

It's a very clear distinction, and should not be a problem.

To reiterate, if a contract fails, that is a BUG in the program, and the program 
is then considered to be in an undefined state and is not recoverable.

CONTRACTS ARE NOT AN ERROR HANDLING MECHANISM.



More information about the Digitalmars-d mailing list