|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "199a314e-264d-40a7-9acc-cf6e1843dba7", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Errors and Exception" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "id": "e6044ca7-f38b-492b-b869-23f5409ac9e1", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "## Error:\n", |
| 17 | + "\n", |
| 18 | + "Errors are the problems in a program due to which the program will stop the execution.\n", |
| 19 | + "\n", |
| 20 | + "[Some Common Errors](https://www.thecrazyprogrammer.com/2014/08/types-of-errors-in-programming.html)\n", |
| 21 | + "\n", |
| 22 | + "1. Syntax Errors\n", |
| 23 | + "2. Run-time Errors\n", |
| 24 | + "3. Logical Errors\n", |
| 25 | + "4. Latent Errors" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "code", |
| 30 | + "execution_count": 10, |
| 31 | + "id": "35bf50f2-6901-4407-a684-415f7ba3f569", |
| 32 | + "metadata": {}, |
| 33 | + "outputs": [ |
| 34 | + { |
| 35 | + "name": "stdout", |
| 36 | + "output_type": "stream", |
| 37 | + "text": [ |
| 38 | + "ArithmeticError\n", |
| 39 | + "AssertionError\n", |
| 40 | + "AttributeError\n", |
| 41 | + "BlockingIOError\n", |
| 42 | + "BrokenPipeError\n", |
| 43 | + "BufferError\n", |
| 44 | + "ChildProcessError\n", |
| 45 | + "ConnectionAbortedError\n", |
| 46 | + "ConnectionError\n", |
| 47 | + "ConnectionRefusedError\n", |
| 48 | + "ConnectionResetError\n", |
| 49 | + "EOFError\n", |
| 50 | + "EnvironmentError\n", |
| 51 | + "FileExistsError\n", |
| 52 | + "FileNotFoundError\n", |
| 53 | + "FloatingPointError\n", |
| 54 | + "IOError\n", |
| 55 | + "ImportError\n", |
| 56 | + "IndentationError\n", |
| 57 | + "IndexError\n", |
| 58 | + "InterruptedError\n", |
| 59 | + "IsADirectoryError\n", |
| 60 | + "KeyError\n", |
| 61 | + "LookupError\n", |
| 62 | + "MemoryError\n", |
| 63 | + "ModuleNotFoundError\n", |
| 64 | + "NameError\n", |
| 65 | + "NotADirectoryError\n", |
| 66 | + "NotImplementedError\n", |
| 67 | + "OSError\n", |
| 68 | + "OverflowError\n", |
| 69 | + "PermissionError\n", |
| 70 | + "ProcessLookupError\n", |
| 71 | + "RecursionError\n", |
| 72 | + "ReferenceError\n", |
| 73 | + "RuntimeError\n", |
| 74 | + "SyntaxError\n", |
| 75 | + "SystemError\n", |
| 76 | + "TabError\n", |
| 77 | + "TimeoutError\n", |
| 78 | + "TypeError\n", |
| 79 | + "UnboundLocalError\n", |
| 80 | + "UnicodeDecodeError\n", |
| 81 | + "UnicodeEncodeError\n", |
| 82 | + "UnicodeError\n", |
| 83 | + "UnicodeTranslateError\n", |
| 84 | + "ValueError\n", |
| 85 | + "WindowsError\n", |
| 86 | + "ZeroDivisionError\n", |
| 87 | + "ArithmeticError\n", |
| 88 | + "AssertionError\n", |
| 89 | + "AttributeError\n", |
| 90 | + "BlockingIOError\n", |
| 91 | + "BrokenPipeError\n", |
| 92 | + "BufferError\n", |
| 93 | + "ChildProcessError\n", |
| 94 | + "ConnectionAbortedError\n", |
| 95 | + "ConnectionError\n", |
| 96 | + "ConnectionRefusedError\n", |
| 97 | + "ConnectionResetError\n", |
| 98 | + "EOFError\n", |
| 99 | + "EnvironmentError\n", |
| 100 | + "FileExistsError\n", |
| 101 | + "FileNotFoundError\n", |
| 102 | + "FloatingPointError\n", |
| 103 | + "IOError\n", |
| 104 | + "ImportError\n", |
| 105 | + "IndentationError\n", |
| 106 | + "IndexError\n", |
| 107 | + "InterruptedError\n", |
| 108 | + "IsADirectoryError\n", |
| 109 | + "KeyError\n", |
| 110 | + "LookupError\n", |
| 111 | + "MemoryError\n", |
| 112 | + "ModuleNotFoundError\n", |
| 113 | + "NameError\n", |
| 114 | + "NotADirectoryError\n", |
| 115 | + "NotImplementedError\n", |
| 116 | + "OSError\n", |
| 117 | + "OverflowError\n", |
| 118 | + "PermissionError\n", |
| 119 | + "ProcessLookupError\n", |
| 120 | + "RecursionError\n", |
| 121 | + "ReferenceError\n", |
| 122 | + "RuntimeError\n", |
| 123 | + "SyntaxError\n", |
| 124 | + "SystemError\n", |
| 125 | + "TabError\n", |
| 126 | + "TimeoutError\n", |
| 127 | + "TypeError\n", |
| 128 | + "UnboundLocalError\n", |
| 129 | + "UnicodeDecodeError\n", |
| 130 | + "UnicodeEncodeError\n", |
| 131 | + "UnicodeError\n", |
| 132 | + "UnicodeTranslateError\n", |
| 133 | + "ValueError\n", |
| 134 | + "WindowsError\n", |
| 135 | + "ZeroDivisionError\n" |
| 136 | + ] |
| 137 | + } |
| 138 | + ], |
| 139 | + "source": [ |
| 140 | + "# list of Errors and exceptions\n", |
| 141 | + "for i in dir(__builtins__) + dir(__builtin__):\n", |
| 142 | + " if \"Error\" in i:\n", |
| 143 | + " print(i)" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "markdown", |
| 148 | + "id": "de9d7e7b-70f5-444f-88b5-a1f77d213d76", |
| 149 | + "metadata": {}, |
| 150 | + "source": [ |
| 151 | + "## Exception:\n", |
| 152 | + "\n", |
| 153 | + "Exceptions are raised when the some internal events occur which changes the normal flow of the program." |
| 154 | + ] |
| 155 | + }, |
| 156 | + { |
| 157 | + "cell_type": "code", |
| 158 | + "execution_count": 9, |
| 159 | + "id": "2b604b7f-9acf-4196-9ce3-45214b38adc8", |
| 160 | + "metadata": {}, |
| 161 | + "outputs": [ |
| 162 | + { |
| 163 | + "name": "stdout", |
| 164 | + "output_type": "stream", |
| 165 | + "text": [ |
| 166 | + "BaseException\n", |
| 167 | + "Exception\n", |
| 168 | + "BaseException\n", |
| 169 | + "Exception\n" |
| 170 | + ] |
| 171 | + } |
| 172 | + ], |
| 173 | + "source": [ |
| 174 | + "# list of Errors and exceptions\n", |
| 175 | + "for i in dir(__builtins__) + dir(__builtin__):\n", |
| 176 | + " if \"Exception\" in i:\n", |
| 177 | + " print(i)" |
| 178 | + ] |
| 179 | + }, |
| 180 | + { |
| 181 | + "cell_type": "markdown", |
| 182 | + "id": "4e8439e0-145b-46a5-9f3f-4624aa99b605", |
| 183 | + "metadata": {}, |
| 184 | + "source": [ |
| 185 | + "## Traceback\n", |
| 186 | + "The script used below is present [here](Errors_and_Exception.py)" |
| 187 | + ] |
| 188 | + }, |
| 189 | + { |
| 190 | + "cell_type": "code", |
| 191 | + "execution_count": 11, |
| 192 | + "id": "5e69d208-e867-431e-a8b1-58669ad3a798", |
| 193 | + "metadata": {}, |
| 194 | + "outputs": [ |
| 195 | + { |
| 196 | + "name": "stdout", |
| 197 | + "output_type": "stream", |
| 198 | + "text": [ |
| 199 | + "In a\n", |
| 200 | + "In b\n" |
| 201 | + ] |
| 202 | + }, |
| 203 | + { |
| 204 | + "ename": "ZeroDivisionError", |
| 205 | + "evalue": "division by zero", |
| 206 | + "output_type": "error", |
| 207 | + "traceback": [ |
| 208 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 209 | + "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", |
| 210 | + "\u001b[1;32m<ipython-input-11-cabfeb6b5ae6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[1;36m42\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", |
| 211 | + "\u001b[1;32m<ipython-input-11-cabfeb6b5ae6>\u001b[0m in \u001b[0;36ma\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"In a\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mb\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Back in a\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", |
| 212 | + "\u001b[1;32m<ipython-input-11-cabfeb6b5ae6>\u001b[0m in \u001b[0;36mb\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"In b\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[1;36m42\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
| 213 | + "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" |
| 214 | + ] |
| 215 | + } |
| 216 | + ], |
| 217 | + "source": [ |
| 218 | + "def a():\n", |
| 219 | + " print(\"In a\")\n", |
| 220 | + " b()\n", |
| 221 | + " print(\"Back in a\")\n", |
| 222 | + "\n", |
| 223 | + "def b():\n", |
| 224 | + " print(\"In b\")\n", |
| 225 | + " return 42/0\n", |
| 226 | + "\n", |
| 227 | + "a() " |
| 228 | + ] |
| 229 | + } |
| 230 | + ], |
| 231 | + "metadata": { |
| 232 | + "kernelspec": { |
| 233 | + "display_name": "Python 3", |
| 234 | + "language": "python", |
| 235 | + "name": "python3" |
| 236 | + }, |
| 237 | + "language_info": { |
| 238 | + "codemirror_mode": { |
| 239 | + "name": "ipython", |
| 240 | + "version": 3 |
| 241 | + }, |
| 242 | + "file_extension": ".py", |
| 243 | + "mimetype": "text/x-python", |
| 244 | + "name": "python", |
| 245 | + "nbconvert_exporter": "python", |
| 246 | + "pygments_lexer": "ipython3", |
| 247 | + "version": "3.9.6" |
| 248 | + } |
| 249 | + }, |
| 250 | + "nbformat": 4, |
| 251 | + "nbformat_minor": 5 |
| 252 | +} |
0 commit comments