TRENDING

Top 22 Python error list



 Here's a comprehensive list of common errors and exceptions in Python, along with their descriptions:

1. Syntax Errors

  • SyntaxError: Occurs when the code violates Python's syntax rules (e.g., missing colons, unmatched parentheses).
  • IndentationError: Triggered when the code is not indented properly.
  • TabError: Raised when inconsistent use of tabs and spaces is found.

2. Name Errors

  • NameError: Occurs when a variable or function name is not found in the local or global scope.
  • UnboundLocalError: A specific type of NameError that occurs when trying to access a local variable before it is assigned a value.

3. Type Errors

  • TypeError: Raised when an operation is applied to an object of an inappropriate type (e.g., adding a string and an integer).
  • TypeError: 'NoneType' object is not iterable: Occurs when trying to iterate over a variable with a None value.

4. Value Errors

  • ValueError: Raised when a function receives an argument of the correct type but an inappropriate value (e.g., passing a non-numeric string to int()).
  • ValueError: too many values to unpack (expected x): Happens when unpacking an iterable with more items than expected.

5. Attribute Errors

  • AttributeError: Occurs when trying to access an attribute that an object does not have.
  • AttributeError: 'NoneType' object has no attribute 'X': Common when trying to access methods or properties on a None object.

6. Index Errors

  • IndexError: Raised when trying to access an index that is out of the bounds of a list or other indexable collection.
  • IndexError: list index out of range: A common error when trying to access a non-existent index in a list.

7. Key Errors

  • KeyError: Occurs when trying to access a dictionary key that does not exist.

8. Import Errors

  • ImportError: Raised when an import statement fails to find the module definition or when the imported module cannot be loaded.
  • ModuleNotFoundError: A more specific subclass of ImportError, raised when a module is not found.

9. IO Errors

  • IOError: Raised when an I/O operation (e.g., reading or writing a file) fails. In modern Python versions, it is an alias for OSError.
  • FileNotFoundError: Raised when trying to open a file that does not exist.
  • IsADirectoryError: Occurs when trying to open a directory as a file.
  • PermissionError: Raised when there is a lack of permissions to perform a file operation.

10. Runtime Errors

  • RuntimeError: A generic error raised when an operation fails, but not for any particular built-in exception type.
  • RecursionError: A subclass of RuntimeError, raised when the maximum recursion depth is exceeded.

11. Overflow and Underflow Errors

  • OverflowError: Raised when a mathematical operation exceeds the limit of the data type.
  • FloatingPointError: Raised when a floating-point operation fails (e.g., division by zero in special configurations).

12. Arithmetic Errors

  • ZeroDivisionError: Raised when dividing by zero.
  • ArithmeticError: The base class for errors related to arithmetic operations, including OverflowError, ZeroDivisionError, and FloatingPointError.

13. Memory Errors

  • MemoryError: Raised when an operation runs out of memory but can be caught so the program can handle it gracefully.

14. Assertion Errors

  • AssertionError: Raised when an assert statement fails.

15. EOF and Keyboard Interrupts

  • EOFError: Raised when the input() function hits an end-of-file condition without reading any data.
  • KeyboardInterrupt: Raised when the user interrupts program execution, usually by pressing Ctrl+C.

16. Stop Iteration

  • StopIteration: Raised by the next() function to indicate that there are no more items in an iterator.

17. System and Environment Errors

  • OSError: Raised for system-related errors, including file system access errors.
  • SystemError: Raised when the Python interpreter detects an internal error.
  • NotImplementedError: Used in abstract methods or classes to indicate that a method must be implemented in a subclass.

18. Warnings

  • Warning: The base class for warning categories.
  • DeprecationWarning: Indicates that a feature is deprecated and will be removed in a future version.
  • UserWarning: A generic warning class for user-defined warnings.
  • SyntaxWarning: Warns of questionable syntax.

19. Connection and Network Errors

  • ConnectionError: The base class for network-related errors.
  • ConnectionRefusedError: Raised when a connection attempt is refused by the server.
  • TimeoutError: Raised when a connection times out.
  • SSLError: Raised for SSL/TLS certificate errors.

20. Custom Exceptions

  • CustomException: You can create custom exceptions by subclassing Python's built-in Exception class for specific error handling in your applications.

21. JSON and Parsing Errors

  • json.decoder.JSONDecodeError: Raised when the json module fails to parse a JSON string.
  • UnicodeDecodeError: Raised when a Unicode-related encoding or decoding error occurs.

22. Other Common Errors

  • TypeError: 'int' object is not callable: Often occurs when a variable name shadows a built-in function, like using int as a variable name.
  • IndentationError: unexpected indent: Indicates that code indentation is not consistent.
  • TypeError: X takes Y positional arguments but Z were given: Function call mismatch between expected and provided arguments.

These errors and exceptions cover most issues you may encounter while coding in Python. Understanding them will help you diagnose and fix problems efficiently.

Post a Comment

0 Comments