堆栈跟踪在Flash / ActionScript 3.0中堆栈、Flash、ActionScript

2023-09-08 12:00:39 作者:混世大魔王

我想看到我的code的任何功能的堆栈跟踪,所以我做了财产以后这样调用它并打印堆栈跟踪:

I want to see the stack trace in any function of my code, so i made somthing like this to call it and print the stack trace:

public function PrintStackTrace() {
    try {
        throw new Error('StackTrace');
    } catch (e:Error) {
        trace(e.getStackTrace());
    }
}

我想知道是否有其他的方法来做到这一点。在一些地方,错误类创建的堆栈跟踪,但也许它并没有使用ActionScript 3.0做到这一点,所以也许它不是更多钞票,但我想知道的。

I like to know if there are other way to do this. In some place, the Error class creates the stack trace, but maybe it didn't do it with ActionScript 3.0 so maybe it's not posible, but i want to know.

谢谢!

推荐答案

据我所知,使堆栈跟踪提供给自己的code的唯一途径是通过的的getStackTrace()方法Error类,就像你已经在做的事情。在回答你的问题的例子,不过,我会提到,你实际上并不不得不放弃错误 - 你可以创建它,并调用它的方法:

As far as I know, the only way to make the stack trace available to your own code is via the getStackTrace() method in the Error class, just like you're already doing. In response to the example in your question, though, I would mention that you don't actually have to throw the Error -- you can just create it and call the method on it:

var tempError:Error = new Error();
var stackTrace:String = tempError.getStackTrace();

此外,如文档中说,在Flash Player的调试版本,这仅适用,这样你就可以在一个if块,检查的Capabilities.isDebugger如果你想要的。