开发者

What's the most reliable way to crash a Flex application?

I need to add some c开发者_如何学Goode that will crash my Flex application if certain conditions are met. I need it to work whatever state the Flex application is in (maybe it's not fully initialized, maybe some components are still being loaded, etc.)

What is the most reliable way to accomplish that?


Try one of unresolved crash bugs, e.g. this one:

public function TestVerify () { 
    try { 
        with (this) { 
            return; 
        } 
    } 
    catch (e) { 
        trace('catch'); 
    } 
    finally { 
        trace('finally'); 
    } 
} 


The comments are kind of dragging along; but I wanted to post some code to prove a point about uncaught exceptions and crashing the app. So, here it is.

If you want to cause an exception, use the throw command and the Error class. The uncaught exception will not crash the app.

Here is an example that you can copy and paste and run.

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
            {
                var error : Error = new Error();
                throw error;
            }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>



    <s:Button />
</s:WindowedApplication>

If you execute this app from Flash Builder, you'll see that you get a "standard" error pop up. But, once you click dismiss you can still click the button and interact with the app.

Having an uncaught Exception is not the same as crashing the app; or preventing users from interacting with the app.

If you just want to prevent users from interacting with the app you should be able to do do something along the lines of FlexGlobals.topLevelApplication.enabled == false; . But, in the comments you keep insisting that is not what you want to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜