Python论坛  - 讨论区

标题:[python-chinese] 请问该如何获取异常的相信信息?

2006年01月11日 星期三 22:59

Young fivesheep at gmail.com
Wed Jan 11 22:59:38 HKT 2006

请问 如何才能在except block中把在try block捕捉到的异常 打印出来(或者保存到文件中). 事先不知道异常种类

try:
    dosth()
except:
    #把异常信息打印出来, 比如这里是方法没定义

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年01月12日 星期四 13:38

Davies Liu davies.liu at gmail.com
Thu Jan 12 13:38:48 HKT 2006

用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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年01月13日 星期五 22:12

黑沙 fred.li.1979.m.bj.prc at gmail.com
Fri Jan 13 22:12:27 HKT 2006

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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年01月13日 星期五 23:28

Young fivesheep at gmail.com
Fri Jan 13 23:28:00 HKT 2006

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
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号