Liquidnight // Jörg Birkhold

Direkt zum Inhalt springen

Liquidnight // Jörg Birkhold

Jörg Birkhold about iOS, Objective-C, Android, FlashPlatform, Multitouch, Flex, Air, 3d Interactive and Software Development

Log

Global Exception Handling in Flex

Maybe someone also ran in the situation that your Flex Application is so big that you can’t be 100% sure that there is no uncatched Runtime Error.
This can get quickly ugly and your app will be reacting totally unpredictable. In the current state of the Flash Player there is no global exeption handling.
There is also a good post about that by Doug Mccune.

Using a try catch block everywhere in Flex it is not so easy because a lot of code is executed async by the callLaterDispatcher.
But after looking around a little I found a Variable in UIComponentGlobals.as called catchCallLaterExceptions.
If you set this to true the callLaterDispatcher will run inside a try catch block, and you can set a listener on the systemManager to catch the Error Event.
This is just little tested from my side so I can’t say for sure that it will work always correctly.

UIComponentGlobals.catchCallLaterExceptions = true;
systemManager.addEventListener("callLaterError",globalExeptionCatcher);

The relevant Code is in UiComponent.as

private function callLaterDispatcher(event:Event):void
    {
        // trace(">>calllaterdispatcher " + this);
        UIComponentGlobals.callLaterDispatcherCount++;
 
        // At run-time, callLaterDispatcher2() is called
        // without a surrounding try-catch.
        if (!UIComponentGlobals.catchCallLaterExceptions)
        {
            callLaterDispatcher2(event);
        }
 
        // At design-time, callLaterDispatcher2() is called
        // with a surrounding try-catch.
        else
        {
            try
            {
                callLaterDispatcher2(event);
            }
            catch(e:Error)
            {
                var callLaterErrorEvent:DynamicEvent = new DynamicEvent("callLaterError");
                callLaterErrorEvent.error = e;
                systemManager.dispatchEvent(callLaterErrorEvent);
            }
        }

But this doesn’t work if there is a EventDispatcher involved in the callStack, as  Luke Bayes points out here.
If this is bug in the AVM2? I don’t think so…
But anyway this means it won’t work for events like creationComplete etc.

  1. ziv schrieb am Juni 18, 2009:

    Wow – it sound interesting!

    where did you add the:
    systemManager.addEventListener(“callLaterError”,globalExeptionCatcher);
    ?
    and what kind of exceptions it catch?

    Thanks!

    Ziv

  2. joerg schrieb am Juni 18, 2009:

    It is in my Main Application. But you can add it anywhere where you can get a reference to the systemManager.
    It catches exeptions from actions which are called from the callLaterDispatcher() i.e. updateDisplayList() etc.

    best
    jörg

RSS-Feed für Kommentare dieses Beitrags.

Einen Kommentar hinterlassen

Erlaubte Tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Mehr Lesen

«
»