Program logic bugs vs input/environmental errors

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 28 21:16:18 PDT 2014


On 09/29/2014 12:59 AM, Walter Bright wrote:
> ...
>
>> Unless, of course, you're suggesting that we put this around every
>> main() function:
>>
>>     void main() {
>>         try {
>>             ...
>>         } catch(Exception e) {
>>             assert(0, "Unhandled exception: I screwed up");
>>         }
>>     }
>
> I'm not suggesting that Exceptions are to be thrown on programmer
> screwups - I suggest the OPPOSITE.
>

He does not suggest that Exceptions are to be thrown on programmer 
screw-ups, but rather that the thrown exception itself is the screw-up, 
with a possibly complex cause.

It is not:

if(screwedUp()) throw Exception("");


It is rather:

void foo(int x){
     if(!test(x)) throw Exception(""); // this may be an expected code 
path for some callers
}

void bar(){
     // ...
     int y=screwUp();
     foo(y); // yet it is unexpected here
}


More information about the Digitalmars-d mailing list