DIP33: A standard exception hierarchy

Lars T. Kyllingstad public at kyllingen.net
Wed Apr 3 02:33:00 PDT 2013


On Wednesday, 3 April 2013 at 09:20:02 UTC, Walter Bright wrote:
> 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.

I completely agree, and this is exactly why we need 
InputArgumentError.

Lars


More information about the Digitalmars-d mailing list