views:

73

answers:

3

Trying to implement the new FP 10.1 Global error handler into my projects but no matter what I do any uncaught error will still show up the Exception window (both in debug and release versions of the SWF). All I want to do is to prevent these popups but instead send a message to my logger. Here's my code ...

EDIT: I simplified the code now. Could somebody do me a favor and test the following class and see if it's works for him? Because it's doesn't for me! ...

package
{
    import flash.display.Sprite;
    import flash.events.UncaughtErrorEvent;


    public class GlobalErrorHandlerTest extends Sprite
    {
        public function GlobalErrorHandlerTest()
        {
            stage.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
            throw new Error();
        }


        private function onUncaughtError(e:UncaughtErrorEvent):void 
        {
            var message:String;
            if (e.error["message"])
            {
                message = e.error["message"];
            }
            else if (e.error["text"])
            {
                message = e.error["text"];
            }
            else
            {
                message = e.error["toString"]();
            }

            trace("Uncaught Error: " + e.text);
        }
    }
}
A: 

You must set up the listener not to a specific view, but to the main stage object, as it's at the top of the display list (thus picking up any exception of any of its children).

HTH

J

Zárate
The 'view' is actually the top-most display object container (it's just given as a property to my Main class). And neither does it work if I use view.stage.loaderInfo.uncaughtErrorEvents.addEventListener...
loungelizard
Hmm any other ideas why the (new) above code wouldn't work?
loungelizard
A: 

Did you get this to work? Same problem here ...

gerrie
A: 

The docs say that:

The UncaughtErrorEvents object that dispatches the event is associated with either a LoaderInfo object or a Loader object.

Thus you must listen to the loaderInfo's uncaughtErrorEvents property of your topmost display object:

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
grapefrukt
Still no luck! I'm out of ideas! Can _anyone_ confirm that the above example works for them??
loungelizard