You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Doc/tutorial/errors.rst
+27-9Lines changed: 27 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -388,15 +388,33 @@ example::
388
388
File "<stdin>", line 2, in <module>
389
389
KeyboardInterrupt
390
390
391
-
If a :keyword:`finally` clause is present, the :keyword:`finally` clause will execute as the last task before the :keyword:`try` statement completes. The :keyword:`finally` clause runs whether or not the :keyword:`try` statement produces an exception. The following points discuss more complex cases when an exception occurs:
392
-
393
-
* If an exception occurs during execution of the :keyword:`!try` clause, the exception may be handled by an :keyword:`except` clause. If the exception is not handled by an :keyword:`except` clause, the exception is re-raised after the :keyword:`!finally` clause has been executed.
394
-
395
-
* An exception could occur during execution of an :keyword:`!except` or :keyword:`!else` clause. Again, the exception is re-raised after the :keyword:`!finally` clause has been executed.
396
-
397
-
* If the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, the :keyword:`finally` clause will execute just prior to the :keyword:`break`, :keyword:`continue` or :keyword:`return` statement's execution.
398
-
399
-
* If a :keyword:`finally` clause includes a :keyword:`return` statement, the :keyword:`finally` clause's :keyword:`return` statement will execute before, and instead of, the :keyword:`return` statement in a :keyword:`try` clause.
391
+
If a :keyword:`finally` clause is present, the :keyword:`!finally`
392
+
clause will execute as the last task before the :keyword:`try`
393
+
statement completes. The :keyword:`!finally` clause runs whether or
394
+
not the :keyword:`!try` statement produces an exception. The following
395
+
points discuss more complex cases when an exception occurs:
396
+
397
+
* If an exception occurs during execution of the :keyword:`!try`
398
+
clause, the exception may be handled by an :keyword:`except`
399
+
clause. If the exception is not handled by an :keyword:`!except`
400
+
clause, the exception is re-raised after the :keyword:`!finally`
401
+
clause has been executed.
402
+
403
+
* An exception could occur during execution of an :keyword:`!except`
404
+
or :keyword:`!else` clause. Again, the exception is re-raised after
405
+
the :keyword:`!finally` clause has been executed.
406
+
407
+
* If the :keyword:`!try` statement reaches a :keyword:`break`,
408
+
:keyword:`continue` or :keyword:`return` statement, the
409
+
:keyword:`!finally` clause will execute just prior to the
410
+
:keyword:`!break`, :keyword:`!continue` or :keyword:`!return`
411
+
statement's execution.
412
+
413
+
* If a :keyword:`!finally` clause includes a :keyword:`!return`
414
+
statement, the returned value will be the one from the
415
+
:keyword:`!finally` clause's :keyword:`!return` statement, not the
416
+
value from the :keyword:`!try` clause's :keyword:`!return`
0 commit comments