Writing an error handler function

When you use a formatter, you can write an error handler function so that the user does not see error messages by default. You can also use an error function for debugging, but not in production because you should guarantee that valid values are passed to the formatter before an application goes into production. The following example shows a simple error handler function:

// This function would be in an MXML file.
function formatWithError(value) : String
{
    var formatted = myFormatter.format(value);
    if (formatted == "")
    {
      if (myFormatter.error != undefined)
      {
        if (myFormatter.error == "Invalid value")
        {
           formatted = "The value used in the format function is not a valid
               value.";
        }
        else
        {
           formatted = "The formatString provided is not a valid formatString.";
        }
      }
    }
    return formatted;
}

Version 1.5

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000730.htm