Starting with Flash Player 10.1 and Adobe AIR 2.0, developers can capture unhandled exceptions and errors globally. Note, however, that it's a best practice to take care of the exceptions where they happen. Global handling should only be used for asynchronous exceptions that you can't really control in any other way, or for diagnosing and logging exceptions that are not being caught locally.

In this article I explain how to catch unhandled exceptions or errors globally using the uncaughtError event. The technique I use is declarative and MXML based; it relies on the Flex-specific [Mixin] metadata tag.

When you're working with Flex and you add an UncaughtErrorEvent.UNCAUGHT_ERROR listener to the loaderInfo object, make sure you do it after FlexEvent.APPLICATION_COMPLETE event has been triggered, otherwise you'll get an error, specifically: Error #1009: Cannot access a property or method of a null object reference .

To simplify this procedure and eliminate the need for all this glue code and configuration code that ends up cluttering the main application class , I created a GlobalExceptionHandler component. The implementation isn't tied to the APPLICATION_COMPLETE event; instead it uses the [Mixin] metadata tag. On top of that you can use it declaratively; for example: