On Tuesday, 11 February 2014 at 05:09:13 UTC, Nick Sabalausky wrote:
    mixin(handleFail!(() => {
        ...user code...
    }));

BTW the ()=> there is unnecessary; when there's no arguments, you can just write { code } and it will be recognized as a function/delegate. So this would work too:

int handleError(void delegate() dg) {
        try dg();
        catch(Throwable t) return 1;
        return 0;
}

int main() {
        return handleError({

        });
}

(or of course, handleError(alias dg)() works too if you add the !).


Still perhaps a bit wordier than installing the handler but I don't think it is too bad.

You could also do something like i do in my cgi.d:

void mymain() { code ... }
mixin HandleError!mymain; // HandleError is a mixin tempalte that provides main(), does arg/exception handling, and returns the right value

Reply via email to