@@ -34,8 +34,8 @@ tuple. Like so:
3434 except (IOError , EOFError ) as e:
3535 print (" An error occurred. {} " .format(e.args[- 1 ]))
3636
37- Another method is to handle individual exception in a separate except
38- block . We can have as many except blocks as we want. Here is an example:
37+ Another method is to handle individual exceptions in separate `` except ``
38+ blocks . We can have as many `` except `` blocks as we want. Here is an example:
3939
4040.. code :: python
4141
@@ -48,8 +48,8 @@ block. We can have as many except blocks as we want. Here is an example:
4848 print (" An error occurred." )
4949 raise e
5050
51- This way if the exception is not handled by the first except block then
52- it is passed on to the second block. Now the last method involves
51+ This way if the exception is not handled by the first `` except `` block then
52+ it may be handled by a following block, or none at all . Now the last method involves
5353trapping ALL exceptions:
5454
5555.. code :: python
@@ -60,18 +60,18 @@ trapping ALL exceptions:
6060 # Some logging if you want
6161 raise
6262
63- This can be helpful when you have no idea about the exception which can
63+ This can be helpful when you have no idea about the exceptions which may
6464be thrown by your program.
6565
66- ``Finally `` clause
66+ ``finally `` clause
6767~~~~~~~~~~~~~~~~~~
6868
69- We wrap our main code in the try clause. After that we wrap some code in
70- except clause which gets executed if an exception occurs in the code
71- wrapped in try clause. But in this example we will use a third clause as
69+ We wrap our main code in the `` try `` clause. After that we wrap some code in
70+ an `` except `` clause which gets executed if an exception occurs in the code
71+ wrapped in the `` try `` clause. In this example we will use a third clause as
7272well which is the ``finally `` clause. The code which is wrapped in the
73- finally clause will run even if no exception occurs . It might be used
74- for cleaning up after a script. Here is a simple example:
73+ `` finally `` clause will run whether or not an exception occurred . It might be used
74+ to perform clean- up after a script. Here is a simple example:
7575
7676.. code :: python
7777
@@ -80,10 +80,10 @@ for cleaning up after a script. Here is a simple example:
8080 except IOError as e:
8181 print (' An IOError occurred. {} ' .format(e.args[- 1 ]))
8282 finally :
83- print (" This would be printed even if no exception occurs !" )
83+ print (" This would be printed whether or not an exception occurred !" )
8484
8585 # Output: An IOError occurred. No such file or directory
86- # This would be printed even if no exception occurs !
86+ # This would be printed whether or not an exception occurred !
8787
8888 ``try/else `` clause
8989~~~~~~~~~~~~~~~~~~~
@@ -108,5 +108,5 @@ example:
108108 # This would only run if no exception occurs.
109109 # This would be printed in every case.
110110
111- The else clause would only run if no exception occurs and it would run
111+ The `` else `` clause would only run if no exception occurs and it would run
112112before the ``finally `` clause.
0 commit comments