Throws an exception in a finally block. : finally « Statement « Flash / Flex / ActionScript






Throws an exception in a finally block.

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){


        try {
          throwTwoExceptions(  );
        } catch (e:Error) {
          trace("External catch: " + e.message);
        }
        
        try {
          throw new Error("Test error 1");
        } finally {
          try {
            throw new Error("Test error 2");
          } catch (e:Error) {
            trace("internal catch: " + e.message); // Never executes because
                                                   // the types don't match.
          }
        }

    }
    public function throwTwoExceptions (  ):void {
      try {
        throw new Error("Test error 1");
      } finally {
        try {
          throw new Error("Test error 2");
        } catch (e:Error) {
          trace("Internal catch: " + e.message);
        }
      }
    }
  }
}

        








Related examples in the same category

1.The finally block can be useful for cleaning up. You can use try and finally together:
2.The finally Block
3.Control-Flow Changes in try/catch/finally
4.Using return in finally