Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Why are Python exceptions named "Error" (e.g. ZeroDivisionError, NameError, TypeError)?

Errors like syntax errors occurring at compile time are called errors and those occurring at runtime are called exceptions.

Yet python exceptions like NameError, TypeError…have their names ending in Error. Why is it so?


1 Answer
Rajendra Dharmkar

We see that most exceptions have their names ending in word ‘error’ pointing that they are errors which is the meaning of exceptions anyway.

Errors in restricted sense are taken to mean syntax errors in python and those errors occurring at run time are called exceptions. As we know that classes do not have ‘class’ in their name; and similarly variables do not have names ending in ‘variable’ and so on. So there is no case that exceptions should have names ending in the word ‘exception’.

Consider this; not all exceptions are errors. SystemExit, KeyboardInterrupt, StopIteration, GeneratorExit are all exceptions and not errors. Indeed, there are a number of exceptions that derive from an exception class named Warning.

One good motivation in naming exceptions with the word ‘error’ may be that it is shorter than ‘exception’ in length and can save few characters in the code without loss of meaning.

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.