Trapping Errors

Error handling and error trapping are big parts of debugging. After all, a bug is a programming error that hasn’t been fixed or can’t be fixed. But not all errors are bugs. An error may simply reflect an operational condition, such as an attempt to divide by zero. The error is not in the programming logic, but in the data. An error message is a developer’s way of saying “This is a condition that we couldn’t prevent, but this is what happened and this is what you should do.” It is the responsibility of the developer to fix errors caused by bugs and to handle errors caused by bad data or adverse runtime conditions (such as a loss of the connection).

try/catch Blocks

The try/catch construct gives server-side service developers an easy way to trap errors where they occur. (See Section 6.5, which covers Server-Side ActionScript; Section 8.6; or the related ColdFusion tags, <cftry> and <cfcatch>, in Chapter 5.)

Tip

Remember, client-side ActionScript does not support try/catch constructs, so you should be diligent in handling possible error conditions in your Flash application.

To reiterate, the server-side try/catch construct works like this: the try block contains the code for which you want to trap any errors as it executes. You are saying “try to execute this code.” If an error occurs, the catch block is executed. It can take whatever action is necessary to handle the error condition. For example, if the application is inserting data into a database, this might be as ...

Get Flash Remoting: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.