User Guide

Example: CustomErrors application 279
If a fatal error occurs during an attempt to validate the employee XML packet, the error
message is displayed in an Alert component, and the
xmlText TextArea component instance
and
validateBtn Button component instance are disabled, as the following code shows:
public function showFatalError(error:FatalError):void
{
var message:String = error.message + "\n\n" + "Click OK to end.";
var title:String = error.getTitle();
Alert.show(message, title);
status.text = "This application has ended.";
this.xmlText.enabled = false;
this.validateBtn.enabled = false;
}
If a warning error instead of a fatal error occurs, the error message is displayed in an Alert
component instance, but the TextField and Button component instances arent disabled. The
showWarningError() method displays the custom error message in the Alert component
instance. The message also asks the user to decide if they want to proceed with validating the
XML or abort the script. The following excerpt shows the
showWarningError() method:
public function showWarningError(error:WarningError):void
{
var message:String = error.message + "\n\n" + "Do you want to exit this
application?";
var title:String = error.getTitle();
Alert.show(message, title, Alert.YES | Alert.NO, null, closeHandler);
status.text = message;
}
When the user closes the Alert component instance by using either the Yes or No button, the
closeHandler() method is invoked. The following excerpt shows the closeHandler()
method:
private function closeHandler(event:CloseEvent):void
{
switch (event.detail)
{
case Alert.YES:
showFatalError(new FatalError(9999));
break;
case Alert.NO:
break;
}
}
If the user chooses to abort the script by clicking Yes in the warning error Alert dialog, a
FatalError is thrown, causing the application to terminate.