How to catch all exceptions in Flex?

前端 未结 9 722
广开言路
广开言路 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:14

    Alternative to accepted answer, using try-catch. Slower, but more straightforward to read, I think.

    try {
        loaderInfo.uncaughtErrorEvents.addEventListener("uncaughtError", onUncaughtError);
    } catch (e:ReferenceError) {
        var spl:Array = Capabilities.version.split(" ");
        var verSpl:Array = spl[1].split(",");
    
        if (int(verSpl[0]) >= 10 &&
            int(verSpl[1]) >= 1) {
            // This version is 10.1 or greater - we should have been able to listen for uncaught errors...
            d.warn("Unable to listen for uncaught error events, despite flash version: " + Capabilities.version);
        }
    }
    

    Of course, you'll need to be using an up-to-date 10.1 playerglobal.swc in order to compile this code successfully: http://labs.adobe.com/downloads/flashplayer10.html

提交回复
热议问题