-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b1438e
commit 7fbaa9a
Showing
12 changed files
with
15,274 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
252 changes: 252 additions & 0 deletions
252
.ipynb_checkpoints/Errors_and_Exception_Handling-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "199a314e-264d-40a7-9acc-cf6e1843dba7", | ||
"metadata": {}, | ||
"source": [ | ||
"# Errors and Exception" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e6044ca7-f38b-492b-b869-23f5409ac9e1", | ||
"metadata": {}, | ||
"source": [ | ||
"## Error:\n", | ||
"\n", | ||
"Errors are the problems in a program due to which the program will stop the execution.\n", | ||
"\n", | ||
"[Some Common Errors](https://www.thecrazyprogrammer.com/2014/08/types-of-errors-in-programming.html)\n", | ||
"\n", | ||
"1. Syntax Errors\n", | ||
"2. Run-time Errors\n", | ||
"3. Logical Errors\n", | ||
"4. Latent Errors" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "35bf50f2-6901-4407-a684-415f7ba3f569", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"ArithmeticError\n", | ||
"AssertionError\n", | ||
"AttributeError\n", | ||
"BlockingIOError\n", | ||
"BrokenPipeError\n", | ||
"BufferError\n", | ||
"ChildProcessError\n", | ||
"ConnectionAbortedError\n", | ||
"ConnectionError\n", | ||
"ConnectionRefusedError\n", | ||
"ConnectionResetError\n", | ||
"EOFError\n", | ||
"EnvironmentError\n", | ||
"FileExistsError\n", | ||
"FileNotFoundError\n", | ||
"FloatingPointError\n", | ||
"IOError\n", | ||
"ImportError\n", | ||
"IndentationError\n", | ||
"IndexError\n", | ||
"InterruptedError\n", | ||
"IsADirectoryError\n", | ||
"KeyError\n", | ||
"LookupError\n", | ||
"MemoryError\n", | ||
"ModuleNotFoundError\n", | ||
"NameError\n", | ||
"NotADirectoryError\n", | ||
"NotImplementedError\n", | ||
"OSError\n", | ||
"OverflowError\n", | ||
"PermissionError\n", | ||
"ProcessLookupError\n", | ||
"RecursionError\n", | ||
"ReferenceError\n", | ||
"RuntimeError\n", | ||
"SyntaxError\n", | ||
"SystemError\n", | ||
"TabError\n", | ||
"TimeoutError\n", | ||
"TypeError\n", | ||
"UnboundLocalError\n", | ||
"UnicodeDecodeError\n", | ||
"UnicodeEncodeError\n", | ||
"UnicodeError\n", | ||
"UnicodeTranslateError\n", | ||
"ValueError\n", | ||
"WindowsError\n", | ||
"ZeroDivisionError\n", | ||
"ArithmeticError\n", | ||
"AssertionError\n", | ||
"AttributeError\n", | ||
"BlockingIOError\n", | ||
"BrokenPipeError\n", | ||
"BufferError\n", | ||
"ChildProcessError\n", | ||
"ConnectionAbortedError\n", | ||
"ConnectionError\n", | ||
"ConnectionRefusedError\n", | ||
"ConnectionResetError\n", | ||
"EOFError\n", | ||
"EnvironmentError\n", | ||
"FileExistsError\n", | ||
"FileNotFoundError\n", | ||
"FloatingPointError\n", | ||
"IOError\n", | ||
"ImportError\n", | ||
"IndentationError\n", | ||
"IndexError\n", | ||
"InterruptedError\n", | ||
"IsADirectoryError\n", | ||
"KeyError\n", | ||
"LookupError\n", | ||
"MemoryError\n", | ||
"ModuleNotFoundError\n", | ||
"NameError\n", | ||
"NotADirectoryError\n", | ||
"NotImplementedError\n", | ||
"OSError\n", | ||
"OverflowError\n", | ||
"PermissionError\n", | ||
"ProcessLookupError\n", | ||
"RecursionError\n", | ||
"ReferenceError\n", | ||
"RuntimeError\n", | ||
"SyntaxError\n", | ||
"SystemError\n", | ||
"TabError\n", | ||
"TimeoutError\n", | ||
"TypeError\n", | ||
"UnboundLocalError\n", | ||
"UnicodeDecodeError\n", | ||
"UnicodeEncodeError\n", | ||
"UnicodeError\n", | ||
"UnicodeTranslateError\n", | ||
"ValueError\n", | ||
"WindowsError\n", | ||
"ZeroDivisionError\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# list of Errors and exceptions\n", | ||
"for i in dir(__builtins__) + dir(__builtin__):\n", | ||
" if \"Error\" in i:\n", | ||
" print(i)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "de9d7e7b-70f5-444f-88b5-a1f77d213d76", | ||
"metadata": {}, | ||
"source": [ | ||
"## Exception:\n", | ||
"\n", | ||
"Exceptions are raised when the some internal events occur which changes the normal flow of the program." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "2b604b7f-9acf-4196-9ce3-45214b38adc8", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"BaseException\n", | ||
"Exception\n", | ||
"BaseException\n", | ||
"Exception\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# list of Errors and exceptions\n", | ||
"for i in dir(__builtins__) + dir(__builtin__):\n", | ||
" if \"Exception\" in i:\n", | ||
" print(i)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "4e8439e0-145b-46a5-9f3f-4624aa99b605", | ||
"metadata": {}, | ||
"source": [ | ||
"## Traceback\n", | ||
"The script used below is present [here](Errors_and_Exception.py)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "5e69d208-e867-431e-a8b1-58669ad3a798", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"In a\n", | ||
"In b\n" | ||
] | ||
}, | ||
{ | ||
"ename": "ZeroDivisionError", | ||
"evalue": "division by zero", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | ||
"\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", | ||
"\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", | ||
"\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", | ||
"\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"def a():\n", | ||
" print(\"In a\")\n", | ||
" b()\n", | ||
" print(\"Back in a\")\n", | ||
"\n", | ||
"def b():\n", | ||
" print(\"In b\")\n", | ||
" return 42/0\n", | ||
"\n", | ||
"a() " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def a(): | ||
print("In a") | ||
b() | ||
print("Back in a") | ||
|
||
def b(): | ||
val = 52 | ||
print("In b") | ||
val | ||
return val | ||
|
||
a() |
Oops, something went wrong.