StackTrace in Flash / ActionScript 3.0

后端 未结 8 1656
青春惊慌失措
青春惊慌失措 2020-11-28 12:52

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(         


        
8条回答
  •  自闭症患者
    2020-11-28 12:52

    I've put together this little function:

    public static function getStackTrace() : String
    {
        var aStackTrace : Array = new Error().getStackTrace().split("\n");
        aStackTrace.shift();
        aStackTrace.shift();
        return "Stack trace: \n" + aStackTrace.join("\n");
    }
    

    I have this function in a custom "Debug" class I use with my apps when developing. The two shift() calls remove the first two lines: The first one is just the string "Error" and the second line refers to this function itself, so it's not useful. You can even remove the third line if you wish (it refers to the line where you place the call to the getStackTrace() function) by adding another shift() call, but I left it to serve as a starting point of the "stack trace".

提交回复
热议问题