What is the difference between except and except BaseException

Practically speaking, there is no difference between except: and except BaseException:, for any current Python release.

That's because you can't just raise any type of object as an exception. The raise statement explicitly disallows raising anything else:

[...] raise evaluates the first expression as the exception object. It must be either a subclass or an instance of BaseException.

Bold emphasis mine. This has not always been the case however, in older Python releases (2.4 and before) you could use strings as exceptions too.

The advantage then is that you get to have easy access to the caught exception. In order to be able to add as targetname, you must catch a specific class of exceptions, and only BaseException is going to do that.

You can still access the currently active exception by using sys.exc_info() though:

except:
    be = sys.exc_info()[1] 

Pick what you feel is more readable for your future self and for your colleagues.


The accepted answer is incorrect incomplete (at least for Python 3.6 and above).

By catching Exception you catch most errors - basically all the errors that any module you use might throw.

By catching BaseException, in addition to all the above exceptions, you also catch exceptions of the types SystemExit, KeyboardInterrupt, and GeneratorExit.

By catching KeyboardInterrupt, for example, you may stop your code from exiting after an initiated exit by the user (like pressing ^C in the console, or stopping launched application on some interpreters). This could be a wanted behavior (for example - to log an exit), but should be used with extreme care!

In the above example, by catching BaseException, you may cause your application to hang when you want it to exit.