except:
accepts all exceptions whereas
except Exception as e:
only accepts exceptions that you must catch.
Here is an example of what you are not going to catch:
>>> try: ... input() ... except: ... pass ... >>> try: ... input() ... except Exception as e: ... pass ... Traceback (most recent call last): File "<stdin>", line 2, in <module> KeyboardInterrupt
The first disabled KeyboardInterrupt !
Here is a quick list:
issubclass(BaseException, BaseException)
If you want to catch any of them, the best thing to do is
except BaseException:
to indicate that you know what you are doing.
All exceptions are related to BaseException , and those that you are going to catch daily (those that will be selected for the programmer) are also inherited from Exception .
Veedrac Sep 24 '13 at 13:17 2013-09-24 13:17
source share