Python Language Exceptions


Errors detected during execution are called exceptions and are not unconditionally fatal. Most exceptions are not handled by programs; it is possible to write programs that handle selected exceptions. There are specific features in Python to deal with exceptions and exception logic. Furthermore, exceptions have a rich type hierarchy, all inheriting from the BaseException type.


  • raise exception
  • raise # re-raise an exception that’s already been raised
  • raise exception from cause # Python 3 - set exception cause
  • raise exception from None # Python 3 - suppress all exception context
  • try:
  • except [exception types] [ as identifier ]:
  • else:
  • finally: