paip. 调试技术打印堆栈 uapi print stack java php python 总结.

paip. 调试技术打印堆栈 uapi print stack java php python 总结.





作者Attilax  艾龙,  EMAIL:1466519819@qq.com

来源:attilax的专栏

地址:http://blog.csdn.net/attilax





---------uapi

打印堆栈:printStack    god.printstack()

得到堆栈String:getStack





----------------php,

debug_print_backtrace(),加入error line的前面行上...

保存stack到文件:print_r(debug_backtrace());









C:\phpdeskc9>D:\wamp\php\php.exe  E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some

_dir.php E:\OfflineExplorerPortable\Download budejie,xiaohua

#0  c() called at [E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some_dir.php:31]

#1  b() called at [E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some_dir.php:27]

#2  a() called at [E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some_dir.php:38]





Fatal error: Call to undefined function d() in E:\DedeCMS-V5.7-UTF8-SP1-Full\upl

oads\del_some_dir.php on line 35









 debug_backtrace() 函数生成一个 backtrace。[1]

该函数返回一个关联数组









------------java 

e.printStackTrace() 





保存stack到文件,方法1

StackTraceElement [] messages=ex.getStackTrace();

   int length=messages.length;

   for(int i=0;i<length;i++){

    System.out.println("ClassName:"+messages[i].getClassName());

    System.out.println("getFileName:"+messages[i].getFileName());

    System.out.println("getLineNumber:"+messages[i].getLineNumber());

    System.out.println("getMethodName:"+messages[i].getMethodName());

    System.out.println("toString:"+messages[i].toString());

    }

   }

   

 保存stack到文件,方法2

public String getTrace(Throwable t) {

        StringWriter stringWriter= new StringWriter();

        PrintWriter writer= new PrintWriter(stringWriter);

        t.printStackTrace(writer);

        StringBuffer buffer= stringWriter.getBuffer();

        return buffer.toString();

    }





------------python

info = traceback.format_exc()

print info





参考:

python异常处理及异常信息追踪 - 趣客(放糖的绿豆汤) - Power by SupDo!.htm

上一篇:【WEB前端】CSS继承性和层叠性(极度重要)


下一篇:Node.js入门