How to properly ignore exceptions

前端 未结 11 2127
粉色の甜心
粉色の甜心 2020-11-22 02:18

When you just want to do a try-except without handling the exception, how do you do it in Python?

Is the following the right way to do it?

try:
    s         


        
11条回答
  •  梦如初夏
    2020-11-22 02:58

    try:
          doSomething()
    except Exception: 
        pass
    else:
          stuffDoneIf()
          TryClauseSucceeds()
    

    FYI the else clause can go after all exceptions and will only be run if the code in the try doesn't cause an exception.

提交回复
热议问题