User Guide
278 Handling Errors
</employee>;
}
The XML packet is later displayed in a TextArea component instance on the Stage. This
allows you to modify the XML packet before attempting to revalidate it.
When the user clicks the Validate button, the
validateData() method is called. This
method validates the employee XML packet using the
validateEmployeeXML() method in
the Validator class. The following code shows the
validateData() method:
public function validateData():void
{
try
{
var tempXML:XML = XML(xmlText.text);
Validator.validateEmployeeXML(tempXML);
status.text = "The XML was successfully validated.";
}
catch (error:FatalError)
{
showFatalError(error);
}
catch (error:WarningError)
{
showWarningError(error);
}
catch (error:Error)
{
showGenericError(error);
}
}
First, a temporary XML object is created using the contents of the TextArea component
instance
xmlText. Next, the validateEmployeeXML() method in the custom Validator class
(com.example.programmingas3/errors/Validator.as) is invoked and passes the temporary
XML object as a parameter. If the XML packet is valid, the
status Label component instance
displays a success message and the application exits. If the
validateEmployeeXML() method
threw a custom error (that is, a FatalError, WarningError, or a generic Error occurred), the
appropriate
catch statement executes and calls either the showFatalError(),
showWarningError(), or showGenericError() methods. Each of these methods displays an
appropriate message in an Alert component to notify the user of the specific error that
occurred. Each method also updates the
status Label component instance with a specific
message.