This chapter will introduce error handling. We'll cover both handling error events raised by various Flex APIs, such as the RPC services, as well as synchronous inline errors with the ActionScript's runtime exception handling. Compiler errors won't be discussed in this chapter.
Handling errors in Flex is a bit of a tricky proposition because of the asynchronous nature of everything. There is no one main function to place a global error trap catching all unhandled exceptions. Furthermore, many error conditions are triggered by specific events that the developer must implement event handlers in order to be notified of, such as various RPC, file uploading, and drag and drop operations. Failure to implement the handler can sometimes result in silent failures.
Let's get started by looking at working with synchronous error handling with ActionScript's exception-handling functionality.
With Flex, you get the same exception handling provided by ActionScript with the
finally statements. With this, you'll be able to handle runtime errors in a given method, or bubble errors up the call stack until an appropriate
try/catch error handler is found. This will be your tool of choice for managing error conditions and exceptions in synchronous code. However, since Flex is based on an asynchronous timeline event model, there are also plenty of error events raised when failures to open files, call out to services, and so on occur. ...