|
114 | 114 | "contributors": [],
|
115 | 115 | "code": "class ExceptionName(BaseException):\n def __init__(message: str):\n super().__init__(message)\n\n# Usage\na: int = 1\n\nif a > 0:\n raise ExceptionName('Error Message')\n"
|
116 | 116 | },
|
117 | | - { |
118 | | - "title": "Handle File Not Found Error", |
119 | | - "description": "Attempts to open a file and handles the case where the file does not exist.", |
120 | | - "author": "axorax", |
121 | | - "tags": [ |
122 | | - "python", |
123 | | - "error-handling", |
124 | | - "file", |
125 | | - "utility" |
126 | | - ], |
127 | | - "contributors": [], |
128 | | - "code": "def read_file_safe(filepath):\n try:\n with open(filepath, 'r') as file:\n return file.read()\n except FileNotFoundError:\n return \"File not found!\"\n\n# Usage:\nprint(read_file_safe('nonexistent.txt')) # Output: 'File not found!'\n" |
129 | | - }, |
130 | 117 | {
|
131 | 118 | "title": "Retry Function Execution on Exception",
|
132 | 119 | "description": "Retries a function execution a specified number of times if it raises an exception.",
|
|
0 commit comments