All instances in Python must be instances of a class that derives from BaseException. Two exception classes that are not related via subclassing are never equivalent, even if they have the same name. The built-in exceptions can be generated by the interpreter or built-in functions.
Here is a list all the standard Exceptions available in Python −
|Sr.No.||Exception Name & Description|
All built-in, non-system-exiting exceptions are derived from this class. All user-defined exceptions should also be derived from this class.
Raised by built-in function next() and an iterator’s __next__() method to signal that there are no further items produced by the iterator.
Raised by the sys.exit() function.
Base class for all built-in exceptions except StopIteration and SystemExit.
The base class for those built-in exceptions that are raised for various arithmetic errors: OverflowError, ZeroDivisionError, FloatingPointError.
Raised when the result of an arithmetic operation is too large to be represented. This cannot occur for integers (which would rather raise MemoryError than give up). However, for historical reasons, OverflowError is sometimes raised for integers that are outside a required range. Because of the lack of standardization of floating point exception handling in C, most floating point operations are not checked.
Raised when a floating point calculation fails.Not currently used.
Raised when division or modulo by zero takes place for all numeric types.
Raised in case of failure of the Assert statement.
assert False, 'The assertion failed'
Raised in case of failure of attribute reference or assignment.
Raised when there is no input from either the raw_input() or input() function and the end of file is reached.
Raised when an import statement fails.
Raised when the user interrupts program execution, usually by pressing Ctrl+c.
Base class for all lookup errors.
Raised when an index is not found in a sequence.
Raised when the specified key is not found in the dictionary.
Raised when an identifier is not found in the local or global namespace.
Raised when trying to access a local variable in a function or method but no value has been assigned to it.
Base class for all exceptions that occur outside the Python environment.
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.
Raised for operating system-related errors.
Raised when there is an error in Python syntax.
Raised when indentation is not specified properly.
Raised when the interpreter finds an internal problem, but when this error is encountered the Python interpreter does not exit.
Raised when Python interpreter is quit by using the sys.exit() function. If not handled in the code, causes the interpreter to exit.
Raised when an operation or function is attempted that is invalid for the specified data type.
Raised when the built-in function for a data type has the valid type of arguments, but the arguments have invalid values specified.
Raised when a generated error does not fall into any category.
Raised when an abstract method that needs to be implemented in an inherited class is not actually implemented.
The class hierarchy for built-in exceptions is:
BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception +-- StopIteration +-- StopAsyncIteration +-- ArithmeticError | +-- FloatingPointError | +-- OverflowError | +-- ZeroDivisionError +-- AssertionError +-- AttributeError +-- BufferError +-- EOFError +-- ImportError | +-- ModuleNotFoundError +-- LookupError | +-- IndexError | +-- KeyError +-- MemoryError +-- NameError | +-- UnboundLocalError +-- OSError | +-- BlockingIOError | +-- ChildProcessError | +-- ConnectionError | | +-- BrokenPipeError | | +-- ConnectionAbortedError | | +-- ConnectionRefusedError | | +-- ConnectionResetError | +-- FileExistsError | +-- FileNotFoundError | +-- InterruptedError | +-- IsADirectoryError | +-- NotADirectoryError | +-- PermissionError | +-- ProcessLookupError | +-- TimeoutError +-- ReferenceError +-- RuntimeError | +-- NotImplementedError | +-- RecursionError +-- SyntaxError | +-- IndentationError | +-- TabError +-- SystemError +-- TypeError +-- ValueError | +-- UnicodeError | +-- UnicodeDecodeError | +-- UnicodeEncodeError | +-- UnicodeTranslateError +-- Warning +-- DeprecationWarning +-- PendingDeprecationWarning +-- RuntimeWarning +-- SyntaxWarning +-- UserWarning +-- FutureWarning +-- ImportWarning +-- UnicodeWarning +-- BytesWarning +-- ResourceWarning
Anmol on Apr 19, 2020 at 12:04 am
This article is contributed by Anmol. If you like dEexams.com and would like to contribute, you can write your article here or mail your article to email@example.com . See your article appearing on the dEexams.com main page and help others to learn.