Purpose of else and finally in exception handling

后端 未结 5 1671
耶瑟儿~
耶瑟儿~ 2020-12-12 23:35

Are the else and finally sections of exception handling redundant? For example, is there any difference between the following two code snippets?

5条回答
  •  一个人的身影
    2020-12-13 00:15

    finally is executed regardless of whether the statements in the try block fail or succeed. else is executed only if the statements in the try block don't raise an exception.

提交回复
热议问题