improving scope(finally/success)
Tomer Filiba via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 3 03:41:29 PST 2015
it'd be really helpful if scope() statements got hold of the
return value or exception, e.g.,
scope(success, retval) {
writeln("the retval is", retval)
}
scope(failure, ex) {
if(typeid(ex) == typeid(MyException)) {
callTheCops();
}
}
it would make logging very easy, and since these statements are
basically code-rewrites i don't suppose it would be hard to
implement. from a syntax point of view:
scope(succes[, VARNAME]) // where VARNAME would be the return
value (a const tmp variable?)
scope(failure[, VARNAME]) // where VARNAME would be hold the
exception (a Throwable)
i mean, code such as
int f() {
scope(exit) writeln("bye");
return 5;
}
is rewritten as something like
int f() {
try {
auto tmp = 5;
}
finally {
writeln("bye");
}
return tmp;
}
so `tmp` is already there for the finally clause (modulo scoping
issues)
More information about the Digitalmars-d
mailing list