Python之异常追踪模块:traceback

正常时输出追踪信息:

import traceback
def stack():
    print 'The python stack:'
    traceback.print_stack()
from twisted.internet import reactor
reactor.callWhenRunning(stack)
reactor.run()

#摘录来自: likebeta. “Twisted与异步编程入门”。 iBooks. 

异常时输出异常消息:

import traceback
try:
    1/0
except Exception,e:
    traceback.print_exc()

#摘录来自:http://www.oschina.net/question/565065_122586

 

posted @ 2015-04-12 18:49  flowjacky  阅读(683)  评论(0编辑  收藏  举报