Return in finally
BCS
BCS at pathlink.com
Wed Mar 7 10:48:51 PST 2007
Frank Benoit (keinfarbton) wrote:
> While programatically porting Java ...
>
> A finally block cannot contain another try/catch block. This is allowed
> in Java. The solution i use is this:
>
> int f(){
> try{
> } finally {
> (){ // start definition of an unnamed function literal
> try{
> } finally {
> // (1)
> }
> }(); // call it.
> }
> return 1;
> }
>
> Now, i have the first time the situation where at (1) a return statement
> occurs. This is not allowed in an a finally block at all [2], and
> withing the function literal it would not end the surrounding function.
>
> Any idea, how to simulate
> 1.) try/catch/finally in a finally
> 2.) make a return from within a finally
> ??
>
>
> [2] not allowed in D, but it is allowed in Java
try
{
...
}
finally
{
...
return;
...
}
|
|
v
try
{
...
}
catch(Object e)
{
...
return;
...
throw e;
}
bad practice in hand work, but this is auto gen code.
More information about the Digitalmars-d
mailing list