Return in finally

Frank Benoit (keinfarbton) benoit at tionex.removethispart.de
Wed Mar 7 12:20:33 PST 2007


// D ==========================
int func(){
  ...
  {
    Tioport_ResultState!(int) tioport_result_001;
    try{
      try{
        // (1)
      } catch( IOException e ){
        // (2)
      }
    } catch( Object e ) {
      // catch and store for rethrow after Finally_001
      tioport_result_001.setException( e );
    }
    Finally_001:
    {
      // (3)
    }
    tioport_result_001.checkException(); // throw if one was stored
    return tioport_result_001.get();
  }
}

In (1) und (2) replace all "return;" with "goto Finally_001;". "return
expr;" with "{ tioport_result_001.set( expr ); goto Finally_001; }"

If in (3) a return or throw occurs, it hides previous returns/throws,
like java does.

This approach do not throw an exception in normal run.

What do you think?
Do I miss a less complicated way?



More information about the Digitalmars-d mailing list