Python Ignore Exception and Go Back to Where I Was

后端 未结 7 1399
孤街浪徒
孤街浪徒 2021-02-13 12:47

I know using below code to ignore a certain exception, but how to let the code go back to where it got exception and keep executing? Say if the exception \'Exception\' raises in

7条回答
  •  遇见更好的自我
    2021-02-13 13:22

    This is pretty much missing the point of exceptions.

    If the first statement has thrown an exception, the system is in an indeterminate state and you have to treat the following statement as unsafe to run.

    If you know which statements might fail, and how they might fail, then you can use exception handling to specifically clean up the problems which might occur with a particular block of statements before moving on to the next section.

    So, the only real answer is to handle exceptions around each set of statements that you want to treat as atomic

提交回复
热议问题