suggestion: finally for return values
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat Dec 9 13:35:34 PST 2006
"Dan" <ddaglas at gmail.com> wrote in message
news:elf8vj$rqs$1 at digitaldaemon.com...
> How about modifying D to accept a finally clause for use with
> function/method
> return values. For example:
>
> int foo(int a, double b) {
> try {
> ...
> return num;
> ...
> } catch (Exception exc) {
> ...
> } finally {
> ...{statements A}...
> } finally(int retval) {
> ...{statements B}...
> }
> }
>
> statements B will execute when the try block executes "return num;",
> passing
> num into the finally clause as "retval". Whether statements A also
> executes
> in this case is up for discussion.
You can do this with 'out' i.e.
int foo(int a, double b)
out(result)
{
...statements B...
}
body
{
try
{
...return num;
}
finally
{
...statements A...
}
}
But being a contract, it'll only be compiled in non-release mode. :|
I supposed one workaround would be to just put the result into a local
variable before returning it, so you can access it in the finally block.
More information about the Digitalmars-d
mailing list