The Blog

Jan 9, 2009

Lack of Top Level Error/Exception Handling in Flash Player 

by Maxim Porges @ 3:04 PM | Link | Feedback (0)

We're getting ready to do a pretty significant re-architecture of our StrikeTracker console for its 2.0 release, and as part of the process we want to put in bullet-proof error notification for when things go bad or slip through QA. StrikeTracker is coded on top of the Flash/Flex platform, so we are limited to the capabilities in the ActionScript 3 language.

Typically, in Java apps I have used a standard three-layer app with service, business, and data slices. Exceptions are dispatched through the usual Java mechanism, some of which can be handled at the various tiers and dealt with without making it up to the user. When things go really bad (when exceptions are either un-trapped due to programmer error or un-trappable because they are unrecoverable such as a database failure) I have used AOP interception to log the unhandled exception and notify appropriate parties.

So, we figured that there would be something similar in the Flash Player. Turns out we were wrong. While there are some basic ways to trap errors in Flash (using try/catch) and error events (using the onError listener on the main Flex Application tag), it is still possible for an asynchronous process to throw an Error outside of a try/catch with no way to trap it. Typically in the consumer Flash Player, unhandled exceptions result in things "not working" (i.e. the app just seems to be unresponsive to the user's demands), but with no notification to the end user of the error that just happened. If you have the Flash Debug Player, you get a modal Error dialog with the stack trace - definitely more useful, but not something that an end user is going to be able to see and report (unless they are running the Debug Player, which is rare). Obviously, neither situation is ideal, especially because an end user may get an error in the consumer player and have no way to let the developer know what broke. Likewise, the developer has no way to trap and log/communicate the error so that they can diagnose and eliminate it (or at least add a handler for it).

There has been a bug/feature request open on Adobe's JIRA site for better exception handling for over eighteen months, but outside of mentions that it might get handled during Flex 3 (which it obviously didn't) there is no firm timeline stated for when this might be resolved. I could understand this being delayed if adding a global error listener would cause backward compatibility issues with existing Flash/Flex apps, but I can't imagine how it could; apps that don't listen to the error channel will continue to not care about the errors as they do today.

So, if you are a Flash/Flex developer and want proper exception management in Flash, go and vote on the issue. Global exception handling is a feature in any self-respecting development platform, and the Flash player should be no exception (pun intended).

NOTE: to vote on any issues in Adobe's bug tracking system you will need to create an account. This only takes a minute to do, and they don't spam you so rest assured that this is a worthwhile exercise for you as a Flash/Flex developer.