How to catch all exceptions in Flex?

前端 未结 9 717
广开言路
广开言路 2020-11-29 23:39

When I run a Flex application in the debug flash player I get an exception pop up as soon as something unexpected happened. However when a customer uses the application he d

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 00:30

    I attached the event listener to the 'root', which worked for me:

    sprite.root.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
    

    In the debug Flash Player this will still error, but in the non-debug version the error will appear in Flash Player's dialog box - and then the handler will respond. To stop the dialog box from appearing, add:

    event.preventDefault();
    

    so:

        private function onUncaughtError(event:UncaughtErrorEvent):void
        {
            event.preventDefault();
            // do something with this error
        }
    

    I was using this in AIR, but I assume it works for standard AS3 projects too.

提交回复
热议问题