@@ -15,7 +15,7 @@ Here is a simple example:
1515 try :
1616 file = open (' test.txt' , ' rb' )
1717 except IOError as e:
18- print (' An IOError occured . {} ' .format(e.args[- 1 ]))
18+ print (' An IOError occurred . {} ' .format(e.args[- 1 ]))
1919
2020 In the above example we are handling only the IOError exception. What
2121most beginners do not know is that we can handle multiple exceptions.
@@ -32,7 +32,7 @@ tuple. Like so:
3232 try :
3333 file = open (' test.txt' , ' rb' )
3434 except (IOError , EOFError ) as e:
35- print (" An error occured . {} " .format(e.args[- 1 ]))
35+ print (" An error occurred . {} " .format(e.args[- 1 ]))
3636
3737 Another method is to handle individual exception in a separate except
3838block. We can have as many except blocks as we want. Here is an example:
@@ -42,10 +42,10 @@ block. We can have as many except blocks as we want. Here is an example:
4242 try :
4343 file = open (' test.txt' , ' rb' )
4444 except EOFError as e:
45- print (" An EOF error occured ." )
45+ print (" An EOF error occurred ." )
4646 raise e
4747 except IOError as e:
48- print (" An error occured ." )
48+ print (" An error occurred ." )
4949 raise e
5050
5151 This way if the exception is not handled by the first except block then
@@ -78,11 +78,11 @@ for cleaning up after a script. Here is a simple example:
7878 try :
7979 file = open (' test.txt' , ' rb' )
8080 except IOError as e:
81- print (' An IOError occured . {} ' .format(e.args[- 1 ]))
81+ print (' An IOError occurred . {} ' .format(e.args[- 1 ]))
8282 finally :
8383 print (" This would be printed even if no exception occurs!" )
8484
85- # Output: An IOError occured . No such file or directory
85+ # Output: An IOError occurred . No such file or directory
8686 # This would be printed even if no exception occurs!
8787
8888 ``try/else `` clause
0 commit comments