python 异常处理

要用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.

posted @ 2018-11-12 15:43  andy_0212  阅读(90)  评论(0编辑  收藏  举报