Return in finally
Frank Benoit (keinfarbton)
benoit at tionex.removethispart.de
Wed Mar 7 11:52:36 PST 2007
If i understand your idea right...
class FinallyException : Object {} // Special excecption to enter a
finally block.
class Throwable : Exception {} // Base of all Java Exceptions
Now, instead of finally use only catch blocks
catch( FinallyException fe ){
...
}
Hm, i need to think more about it...
The FinallyException can be used to transport a thrown exception
At (1),(2) and (3) a return(val) or throw can happen.
// Java ==========================
try{
// (1)
} catch( IOException e ){
// (2)
} finally {
// (3)
}
// D ==========================
auto fe = new FinallyException();
try{
try{
// (1)
throw fe;
} catch( IOException e ){
try{
// (2)
} catch( Object e ) {
fe.store(e);
throw fe;
}
}
}catch( FinallyException fe ){
// (3)
}
fe.throwIfHasException();
Does this work? oh, my brain hurts :)
Another thought, what about the performance, if an exception is always
thrown to reach the "finally" block? is that an issue?
More information about the Digitalmars-d
mailing list