Catching Errors Generated by Flash : try catch « Statement « Flash / Flex / ActionScript






Catching Errors Generated by Flash

 

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

        var object:Object = "Definitely Not a Display Object";
        try
        {
            var displayObject:DisplayObject = DisplayObject(object);
        } catch (error:TypeError) {
            trace("Incompatible cast!");
            displayObject = new Sprite();
        }
        addChild(displayObject);

    }
  }
}

        








Related examples in the same category

1.Working with Basic try/catch Statements
2.Multiple throw statements and multiple catch statements
3.Using return in try, after throw
4.Using return in catch
5.Catch Blocks Example