2006年01月11日 星期三 22:59
请问 如何才能在except block中把在try block捕捉到的异常 打印出来(或者保存到文件中). 事先不知道异常种类 try: dosth() except: #把异常信息打印出来, 比如这里是方法没定义
2006年01月12日 星期四 13:38
用traceback模块 在06-1-11,Young <fivesheep at gmail.com> 写道: > > 请问 如何才能在except block中把在try block捕捉到的异常 打印出来(或者保存到文件中). 事先不知道异常种类 > > try: > dosth() > except: > #把异常信息打印出来, 比如这里是方法没定义 > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- Davies Liu My Blog: http://blog.daviesliu.net/ My MSN: davies616 at msn.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060112/79af0577/attachment-0001.htm
2006年01月13日 星期五 22:12
first I advice you see the python manual! second is the answer:(copy from this manual) import sys print sys.exc_info() These details are also available through the sys.exc_info() function, which returns a tuple (exc_type, exc_value, exc_traceback). Use of the corresponding variables is deprecated in favor of this function, since their use is unsafe in a threaded program. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060113/ed4f3d10/attachment.htm
2006年01月13日 星期五 23:28
thx anyways. the traceback module is exactly what i want On 1/13/06, 黑沙 <fred.li.1979.m.bj.prc at gmail.com> wrote: > first I advice you see the python manual! > > second is the answer:(copy from this manual) > > > import sys > print sys.exc_info() > > These details are also available through the sys.exc_info() function, which > returns a tuple (exc_type, exc_value, exc_traceback). Use of the > corresponding variables is deprecated in favor of this function, since their > use is unsafe in a threaded program. > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to > python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request at lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > >
Zeuux © 2025
京ICP备05028076号