Custom default exception handler?
Adam D. Ruppe
destructionator at gmail.com
Tue Feb 11 07:00:28 PST 2014
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
More information about the Digitalmars-d-learn
mailing list