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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值