@@ -101,29 +101,29 @@ The :keyword:`try` statement works as follows.
101101* If no exception occurs, the *except clause * is skipped and execution of the
102102 :keyword: `try ` statement is finished.
103103
104- * If an exception occurs during execution of the try clause, the rest of the
105- clause is skipped. Then if its type matches the exception named after the
106- :keyword: `except ` keyword, the except clause is executed, and then execution
107- continues after the :keyword: ` try ` statement .
104+ * If an exception occurs during execution of the :keyword: ` try ` clause, the rest of the
105+ clause is skipped. Then, if its type matches the exception named after the
106+ :keyword: `except ` keyword, the * except clause * is executed, and then execution
107+ continues after the try/except block .
108108
109- * If an exception occurs which does not match the exception named in the except
110- clause, it is passed on to outer :keyword: `try ` statements; if no handler is
109+ * If an exception occurs which does not match the exception named in the * except
110+ clause * , it is passed on to outer :keyword: `try ` statements; if no handler is
111111 found, it is an *unhandled exception * and execution stops with a message as
112112 shown above.
113113
114- A :keyword: `try ` statement may have more than one except clause, to specify
114+ A :keyword: `try ` statement may have more than one * except clause * , to specify
115115handlers for different exceptions. At most one handler will be executed.
116- Handlers only handle exceptions that occur in the corresponding try clause, not
117- in other handlers of the same :keyword: `!try ` statement. An except clause may
118- name multiple exceptions as a parenthesized tuple, for example::
116+ Handlers only handle exceptions that occur in the corresponding * try clause *,
117+ not in other handlers of the same :keyword: `!try ` statement. An * except clause *
118+ may name multiple exceptions as a parenthesized tuple, for example::
119119
120120 ... except (RuntimeError, TypeError, NameError):
121121 ... pass
122122
123123A class in an :keyword: `except ` clause is compatible with an exception if it is
124124the same class or a base class thereof (but not the other way around --- an
125- except clause listing a derived class is not compatible with a base class). For
126- example, the following code will print B, C, D in that order::
125+ * except clause * listing a derived class is not compatible with a base class).
126+ For example, the following code will print B, C, D in that order::
127127
128128 class B(Exception):
129129 pass
@@ -144,10 +144,10 @@ example, the following code will print B, C, D in that order::
144144 except B:
145145 print("B")
146146
147- Note that if the except clauses were reversed (with ``except B `` first), it
148- would have printed B, B, B --- the first matching except clause is triggered.
147+ Note that if the * except clauses * were reversed (with ``except B `` first), it
148+ would have printed B, B, B --- the first matching * except clause * is triggered.
149149
150- The last except clause may omit the exception name(s), to serve as a wildcard.
150+ The last * except clause * may omit the exception name(s), to serve as a wildcard.
151151Use this with extreme caution, since it is easy to mask a real programming error
152152in this way! It can also be used to print an error message and then re-raise
153153the exception (allowing a caller to handle the exception as well)::
@@ -167,9 +167,9 @@ the exception (allowing a caller to handle the exception as well)::
167167 raise
168168
169169The :keyword: `try ` ... :keyword: `except ` statement has an optional *else
170- clause *, which, when present, must follow all except clauses. It is useful for
171- code that must be executed if the try clause does not raise an exception. For
172- example::
170+ clause *, which, when present, must follow all * except clauses * . It is useful
171+ for code that must be executed if the * try clause * does not raise an exception.
172+ For example::
173173
174174 for arg in sys.argv[1:]:
175175 try:
@@ -189,7 +189,7 @@ When an exception occurs, it may have an associated value, also known as the
189189exception's *argument *. The presence and type of the argument depend on the
190190exception type.
191191
192- The except clause may specify a variable after the exception name. The
192+ The * except clause * may specify a variable after the exception name. The
193193variable is bound to an exception instance with the arguments stored in
194194``instance.args ``. For convenience, the exception instance defines
195195:meth: `__str__ ` so the arguments can be printed directly without having to
@@ -217,8 +217,8 @@ If an exception has arguments, they are printed as the last part ('detail') of
217217the message for unhandled exceptions.
218218
219219Exception handlers don't just handle exceptions if they occur immediately in the
220- try clause, but also if they occur inside functions that are called (even
221- indirectly) in the try clause. For example::
220+ * try clause * , but also if they occur inside functions that are called (even
221+ indirectly) in the * try clause * . For example::
222222
223223 >>> def this_fails():
224224 ... x = 1/0
0 commit comments