File tree 1 file changed +36
-1
lines changed
1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change
1
+ # something more about try except
2
+ # basic syntax
3
+ '''
4
+ try:
5
+ code1
6
+
7
+ except:
8
+ some code that will execute if code 1 fails or raise some error
9
+
10
+ else:
11
+ this code is executed only if try was succesful i.e no error in code1
12
+
13
+ finally:
14
+
15
+ this code will execute in every situation if try fails or not
16
+ '''
17
+
1
18
filename = 'exception_data.txt'
2
19
# Outer try block catches file name or file doesn't exist errors.
3
20
try :
@@ -28,4 +45,22 @@ def this_fails():
28
45
try :
29
46
this_fails ()
30
47
except ZeroDivisionError as err :
31
- print ('Handling run-time error:' , err )
48
+ print ('Handling run-time error:' , err )
49
+
50
+
51
+ def divide_me (n ):
52
+ x = 1 / n
53
+
54
+ i = int (input ('enter a number ' ))
55
+ try :
56
+ divide_me (i )
57
+
58
+ except Exception as e :
59
+ print (e ) # this will print the error msg but don't kill the execution of program
60
+
61
+ else :
62
+ print ('Your Code Run Successfully' ) # this will execute if divide_me(i) run sucessfully without an error
63
+
64
+ finally :
65
+ print ('thanks' ) # this will execute in every condition
66
+
You can’t perform that action at this time.
0 commit comments