开发者

Continuing code execution after error in Actionscript 3

开发者 https://www.devze.com 2023-02-26 07:41 出处:网络
I want to be able to throw an error to 开发者_JS百科be traced to the trace output window and to my flashlog.txt file but continue code execution after the error. Is this possible in Actionscript 3? A

I want to be able to throw an error to 开发者_JS百科be traced to the trace output window and to my flashlog.txt file but continue code execution after the error. Is this possible in Actionscript 3? A try catch will not work either because I need the error to be logged with its call stack.


If by trace output window you mean the window that pops up when an Error is thrown (as opposed to the trace window in the Flash IDE, Flash Builder, etc), there's a bit hackish workaround. Basically, you have to delay the call to throw so it runs in its own stack call.

Something like this should do it:

    public static function throwLater(error:Error):void 
    {
        setTimeout(function():void {
            throw error;
        },30);
    } 

Of course you have to pass the error to this function, instead of throwing it directly.

If you just want to get the stack trace from an existent error, though, catch it and get the stack trace as The_asMan showed.

        try {
            thisFunctionMightThrow()
        } catch (e:Error) {
            trace(e.getStackTrace();
        }

Also, if you just want to have the stack trace at some point (but don't want to actually throw an error), just create the error and call getStackTrace, without throwing. In this case, you don't really need a catch.

        var error:Error = new Error();
        trace(e.getStackTrace());


Of course it will work in a try catch just put this code in the catch block

var e:Error = new Error(“Some error”);
trace(e.getStackTrace());
0

精彩评论

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

关注公众号