Understanding Error Objects: throw new Error(); : Error « Development « Flash / Flex / ActionScript






Understanding Error Objects: throw new Error();

 

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

        var sUsername:String = "";
        try {
          if(sUsername == "") {
            throw new Error("Missing Username.");
          }
        }
        catch (erObject:Error) {
          trace(erObject.message);  // Displays: Missing Username.
        }

    }
  }
}

        








Related examples in the same category

1.Handling Errors
2.Throw an exception from a method