try/catch idiom in std.datetime

Walter Bright newshound2 at digitalmars.com
Mon Nov 18 14:49:38 PST 2013


On 11/18/2013 2:37 PM, Andrei Alexandrescu wrote:
> On 11/18/13 1:50 PM, Walter Bright wrote:
>> I believe this is solving the problem in the wrong place. The function
>> being called should not be throwing, and should be defined as not
>> throwing. See my other posts in this thread on the topic.
>
> I think a stance of unceremoniously halting the program upon passing the wrong
> parameters to a standard library function is a bit excessive.

Dang, I gotta argue this with you too? :-)

Forget the philosophical argument for the moment and let's try a pragmatic one - 
code that doesn't check its arguments and doesn't throw is going to inline 
better, run faster, and be smaller. To have a high performance language, we have 
to have this.

This is why we have a -release switch: so we can run with or without checking 
the arguments for bugs.

Input data validation is where exceptions come in. Those are relatively rare 
compared with processing validated data, and so separating out the slow data 
validation path from the validated high speed path makes pragmatic sense.

Rejecting this approach throws (!) out the whole concept of contract programming.



More information about the Digitalmars-d mailing list