9/10/26About 1 minAbout 191 words
Concept: Common exception types
| Exception | Description |
|---|---|
SyntaxError | Raised when the parser encounters a syntax error. This type of error is usually detected by an editor or IDE. |
NameError | Raised when a local or global name is not found. This error occurs when you try to use a variable that has not been defined. |
TypeError | Raised when an operation or function is applied to an object of inappropriate type. For example, trying to add a string and an integer. |
ValueError | Raised when a function receives an argument of the right type but an inappropriate value. For example, trying to convert a string that does not represent a number into an integer. |
IndexError | Raised when a sequence subscript is out of range. For example, trying to access the 10th element of a list that only has 5 elements. |
KeyError | Raised when a dictionary key is not found. For example, trying to access a key that does not exist in a dictionary. |
ZeroDivisionError | Raised when the second argument of a division or modulo operation is zero. For example, trying to divide a number by zero. |