Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are Python exceptions named "Error"?

Why are Python exceptions named "Error" (e.g. ZeroDivisionError, NameError, TypeError) and not "Exception" (e.g. ZeroDivisionException, NameException, TypeException).

I come from a Java background and started to learn Python recently, as such this is confusing because in Java there is a distinction between errors and exceptions.

Is there a difference in Python also or not?

like image 843
Elena Avatar asked May 25 '10 10:05

Elena


People also ask

Why name error occurs in Python?

NameErrors are raised when your code refers to a name that does not exist in the current scope. For example, an unqualified variable name. The given code is rewritten as follows to catch the exception and find its type.

What are exception errors in Python?

Python Logical Errors (Exceptions)Errors that occur at runtime (after passing the syntax test) are called exceptions or logical errors.

Is exception and error the same in Python?

An Error might indicate critical problems that a reasonable application should not try to catch, while an Exception might indicate conditions that an application should try to catch. Errors are a form of an unchecked exception and are irrecoverable like an OutOfMemoryError , which a programmer should not try to handle.

How do you get rid of name errors in Python?

The NameError can be avoided by using a technique called Exception Handling. Even if we write code without any SyntaxError, the program can result in runtime errors. These are called Exceptions. There are numerous built-in exceptions available in Python, and One such exception is NameError Exception.


1 Answers

  1. You don't name each class with 'Class' in name and each variable with '_variable' in name. The same way you don't name exception using the word 'Exception'. A name should say something about the meaning of an object. 'Error' is the meaning of most exceptions.

  2. Not all Exceptions are Errors. SystemExit, KeyboardInterrupt, StopIteration, GeneratorExit are all exceptions and not errors. The word 'Error' in actual errors shows the difference.

  3. 'Error' is shorter than 'Exception'. That can save a few characters in the code width with no loss in meaning. That makes some difference.

like image 149
Jacek Konieczny Avatar answered Oct 02 '22 14:10

Jacek Konieczny