From 9e8dccbc80ea21ee72a46fc55b100aa62384387c Mon Sep 17 00:00:00 2001 From: Saqib Bedar <124094939+saqibbedar@users.noreply.github.com> Date: Wed, 30 Sep 2026 02:37:50 +0500 Subject: [PATCH 1/2] docs(exceptions): add most used python exception list --- exceptions/exception_list.md | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 exceptions/exception_list.md diff --git a/exceptions/exception_list.md b/exceptions/exception_list.md new file mode 100644 index 0000000..0fed523 --- /dev/null +++ b/exceptions/exception_list.md @@ -0,0 +1,49 @@ +# Most Used Built-in Python Exceptions + +### 1. Value and Type Errors + +* `ValueError`: Raised when a function receives an argument with the right type but an inappropriate value (e.g., `int("xyz")`). +* `TypeError`: Raised when an operation or function is applied to an object of an inappropriate type (e.g., `len(5)`). + +### 2. Data Structure Errors + +* `IndexError`: Raised when a sequence subscript (like a list index) is out of range. +* `KeyError`: Raised when a mapping (dictionary) key is not found in the set of existing keys. +* `AttributeError`: Raised when an attribute reference or assignment fails (e.g., trying to call a string method on an integer). + +### 3. Math and Calculation Errors + +* `ZeroDivisionError`: Raised when the second argument of a division or modulo operation is zero. +* `OverflowError`: Raised when the result of an arithmetic operation is too large to be represented. + +### 4. File and Environment Errors + +* `FileNotFoundError`: Raised when a file or directory is requested but does not exist. +* `PermissionError`: Raised when trying to run an operation without the adequate access rights. +* `OSError`: A base class for system-related errors (like disk full, network errors, etc.). + +### 5. Program Flow and Control Errors + +* `StopIteration`: Raised by built-in next() to signal that an iterator has no further items. +* `KeyboardInterrupt`: Raised when the user hits the interrupt key (normally `Ctrl+C`). +* `ImportError`: Raised when the `import` statement has troubles trying to load a module. +* `ModuleNotFoundError`: A subclass of ImportError raised when a module cannot be located. + + +### Example + +```py +def floor_division(a: int, b: int) -> int: + + if b == 0: + raise ZeroDivisionError("Cannot divide a number by zero.") + + return a // b + +try: + print(floor_division(10, 0)) +except ZeroDivisionError as e: + print("Error:", e) +finally: + print("--- Task completed ---") +``` \ No newline at end of file From 0be60a4b86c7cab28f6a0bccfbb7dc52106fbca0 Mon Sep 17 00:00:00 2001 From: Saqib Bedar <124094939+saqibbedar@users.noreply.github.com> Date: Wed, 30 Sep 2026 02:53:01 +0500 Subject: [PATCH 2/2] fix(exceptions): format code with ruff and all tests are passed --- exceptions/exception_list.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exceptions/exception_list.md b/exceptions/exception_list.md index 0fed523..c08eefc 100644 --- a/exceptions/exception_list.md +++ b/exceptions/exception_list.md @@ -34,12 +34,13 @@ ```py def floor_division(a: int, b: int) -> int: - + if b == 0: raise ZeroDivisionError("Cannot divide a number by zero.") return a // b + try: print(floor_division(10, 0)) except ZeroDivisionError as e: