Flash/ActionScript 3.0 中的 StackTrace [英] StackTrace in Flash / ActionScript 3.0

查看:29
本文介绍了Flash/ActionScript 3.0 中的 StackTrace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的代码的任何函数中看到堆栈跟踪,所以我做了这样的事情来调用它并打印堆栈跟踪:

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());
    }
}

我想知道是否有其他方法可以做到这一点.在某些地方,Error 类创建了堆栈跟踪,但也许它没有在 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.

谢谢!

推荐答案

据我所知,使堆栈跟踪可用于您自己的代码的唯一方法是通过 getStackTrace() 方法,就像您已经在做的那样.不过,在回答您问题中的示例时,我会提到您实际上不必抛出错误 - 您只需创建它并在其上调用方法即可:

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 的调试版本,因此您可以将此功能包装在检查 Capabilities.isDebugger(如果需要).

Also, like the documentation says, this only works in the debug version of Flash Player, so you can wrap this functionality in an if-block that checks the value of Capabilities.isDebugger if you want.

这篇关于Flash/ActionScript 3.0 中的 StackTrace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆