File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ try :
2+ raise RuntimeError
3+ print ("try something" )
4+ except RuntimeError :
5+ print ("handling runtime exception" )
6+ finally :
7+ print ("finally" )
Original file line number Diff line number Diff line change 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" )
Original file line number Diff line number Diff line change 1+
2+ try :
3+ raise RuntimeError
4+ print ("try something" )
5+ finally :
6+ print ("finally" )
Original file line number Diff line number Diff line change 1+ # To stop Finally block abruptly
2+
3+ try :
4+ raise RuntimeError
5+ print ("try something" )
6+ finally :
7+ raise RuntimeError
8+ print ("finally" )
Original file line number Diff line number Diff line change 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" )
Original file line number Diff line number Diff line change 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" )
You can’t perform that action at this time.
0 commit comments