Hacker News new | past | comments | ask | show | jobs | submit login

> Caller can add a throws declaration themselves and catch anything.

You are right. I meant someone in the call stack has to catch, not the immediate caller.

That I mentioned null pointers is a red herring. I want to add a block that tells the compiler "prove that no exceptions (checked or unchecked, not even NPE)" can escape outside of this block!".

The escape hatch is about this: imagine you have a function that throws if the argument is odd, but you know you will only call it with an even number:

    void myFunc(int i) never_throws {
        swear_never_throws(NumberOddException) {
            throwsIfOdd(i*2);
        }
    }
(Apologies for the pseudo-code, I haven't made up a nice syntax.) If you mark your function that no exception can escape (not even an unchecked exception!), but the compiler sees that throwsIfOdd can throw NumberOddException, you must of course assert that what you are doing is OK.



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: