首页 > 编程语言 > 详细

python 异常处理

时间:2018-11-12 16:27:49      阅读:132      评论:0      收藏:0      [点我收藏+]

要用exception

下面的代码可以处理异常

        try:
            # ‘65046A‘
            bom = input(Pleaes enter bit BOM: )
            if bom == exit:
                break
            evaluate_bom(bom)
        except Exception as e:
            print(Error:, e)
        finally:
            pass

 

下面的代码不会

        try:
            # ‘65046A‘
            bom = input(Pleaes enter bit BOM: )
            if bom == exit:
                break
            evaluate_bom(bom)
        finally:
            pass

From the Python documentation:

If the finally clause raises another exception or executes a return or break statement, the saved exception is lost.

python 异常处理

原文:https://www.cnblogs.com/andy-0212/p/9946867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!