Python Errors and Built in Exception

Python Errors and Built in Exception


In this section we learn about the Python built in exceptions. For example an exception can be raised by dividing a number by zero. The exceptions can also be raised by the illegal functions.

The errors that are occurred in run time are also called exceptions.

Suppose we used the ‘if statement’ and did not put a colon after its definition then an error will be occurred and this will be called syntax error or parsing error.

Some of the Python built in exceptions are listed below with description:

Exception Cause
AssertionError It is raised when an assert is failed.
AttributeError It is caused when an attribute assignment is failed.
EOFError This is caused when the input () function reaches the end of file.
FloatingPointError It is caused when the floating point operation is failed.
GeneratorExits It is caused when the generator close () method is called.
ImportError This is caused when the imported module cannot be found.
IndexError This is caused when the user specifies the wrong index that can be out of range.
KeyError This is caused when the interpreter cannot find the key in the dictionary.
KeyBoardInterrupt This is caused when the user enters the interrupt key that can be the delete key.
MemoryError This is caused when an operation is failed or runs out of the memory.
NameError This is caused when the interpreter cannot find any variable in the local or in the global scope.
NotImplementedError This is caused when an abstract method is called.
OSError This is caused when the system operation causes an error that is related to the system.
OverflowError This is caused when the result after performing the arithmetic operation is too large.
ReferenceError This is caused when the user uses a weak reference to access the garbage collected reference.
RunTimeError When an error is not of any other category then the run time error is raised.
StopIteration This is caused when we use the next () function to indicate that there are no more iterators that should be returned.
SyntaxError This is caused when a wrong syntax is used.
IndentationError This is caused when we use incorrect indentations in our program.
TabError This is caused when there are useless spaces in the indentation.
SystemError This is caused when an internal error is detected by the interpreter.
TypeError This is caused when a function or operation of wrong type is performed.
UnboundLocalError This is caused when the user references to a local variable.
UnicodeError This is caused when an error during encoding and decoding of Unicode is occurred.
UniEncodeError This is caused when an error during encoding of Unicode is occurred.
UnicodeDecodeError This is caused when an error during decoding of Unicode is occurred.
UnicodeTranslateError This is caused when an error during translating of Unicode is occurred.
ValueError  This is caused when a function is passed an argument of the correct data type but wrong value.
ZeroDivisionError This is caused when a number is tried to be divided by zero.