Skip to content

Commit a1450d6

Browse files
committed
exception handling
1 parent 7fc0b3d commit a1450d6

6 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎Exception_handling/lecture_1.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
try:
2+
raise RuntimeError
3+
print("try something")
4+
except RuntimeError:
5+
print("handling runtime exception")
6+
finally:
7+
print("finally")

‎Exception_handling/lecture_2.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# even after 8th line throwing error finally block will execute
2+
3+
try:
4+
raise RuntimeError
5+
print("try something")
6+
except RuntimeError:
7+
print("handling runtime exception")
8+
raise RuntimeError
9+
print("handling error again")
10+
finally:
11+
print("finally")

‎Exception_handling/lecture_3.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
try:
3+
raise RuntimeError
4+
print("try something")
5+
finally:
6+
print("finally")

‎Exception_handling/lecture_4.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# To stop Finally block abruptly
2+
3+
try:
4+
raise RuntimeError
5+
print("try something")
6+
finally:
7+
raise RuntimeError
8+
print("finally")

‎Exception_handling/lecture_5.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# try except and else
2+
3+
try:
4+
print("try something")
5+
except RuntimeError:
6+
print("handling runtime exception")
7+
else:
8+
print("No exception found")
9+
10+
try:
11+
print("try something")
12+
raise RuntimeError
13+
except RuntimeError:
14+
print("handling runtime exception")
15+
else:
16+
print("No exception found")

‎Exception_handling/lecture_6.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# TO handle custom exception we need to create a class of it
2+
# To make to a Exception we need o inherit from base Exception class
3+
4+
class TranscationFailed(Exception):
5+
def __init__(self,message):
6+
self.message = message
7+
8+
try:
9+
print("try something")
10+
raise TranscationFailed("failed transcation")
11+
except RuntimeError:
12+
print("Runtime Error")
13+
else:
14+
print("some other exception")

0 commit comments

Comments
 (0)