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
}

Reply via email to