From:How to properly ignore Exceptions?
try:
doSomething()
except:
pass
or
try:
doSomething()
except Exception:
pass
区别:
代码1将捕获KeyboardInterrupt、SystemExit等由exceptions.BaseException直接派生出的类似异常。
代码2将捕获由exceptions.Exception直接派生出的异常。
如果需要捕获所有异常,catch Exception而不是仅仅使用except:语句。
except:语句会捕获包括SystemExit的异常。
例如:
>>> try:
... sys.exit(1)
... except:
... pass
...
>>>
>>> try:
... sys.exit(1)
... except Exception:
... pass
...
shell:~$