Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Exception handling in python
  5. Exception


Errors and exceptions are similar but different terms.

While error represents, any bug in the code that disrupt running of the program or cause improved output.

An exception refers to any irregular situation occurring during run time, which we have no control on.

Some built-in exceptions are given below:-

  • EOFError- Raised when of the built-in functions (input()) hits an end of file condition without reading any data.
  • NameError- Raised when an identifier name is not found.
  • IndexError- Raised when an index is not found in a sequence.
  • IOError- Raised when an input/ output operation fails, such as the print statement or the open() function when trying to open a file that does not exist.
  • ImportError- Raised when an import statement fails to find the module definition.
  • TypeError- Raised when an import statement fails to find the module definition.
  • ValueError- Raised when a built-in operation or function receives an argument with an inappropriate value.
  • ZeroDivisionError- Raised when the second argument of a division or module operation is zero.
  • OverFlowError- Raised when the result of an arithmetic operation is too large to be represented.
  • KeyError- Raised when a mapping(Dictionary) key is not found in the set of existing keys.
  • RunTimeError- When the generated error does not fall into any category.
  • SyntaxError- Raised when there is an error in python syntax.
  • IndentationError- Raised when indentation is not specified properly.

There are many more such exceptions.

This is all about exceptions in python.

Was this article helpful to you? Yes No

How can we help?