Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11ca77e

Browse files
committed
Doc for PEP 341, needs improvement
1 parent 58f46b6 commit 11ca77e

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

Doc/ref/ref7.tex

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,25 @@ \section{The \keyword{try} statement\label{try}}
195195
code for a group of statements:
196196

197197
\begin{productionlist}
198-
\production{try_stmt}
199-
{\token{try_exc_stmt} | \token{try_fin_stmt}}
200-
\production{try_exc_stmt}
198+
\production{try_stmt} {try1_stmt | try2_stmt}
199+
\production{try1_stmt}
201200
{"try" ":" \token{suite}}
202201
\productioncont{("except" [\token{expression}
203202
["," \token{target}]] ":" \token{suite})+}
204203
\productioncont{["else" ":" \token{suite}]}
205-
\production{try_fin_stmt}
206-
{"try" ":" \token{suite}
207-
"finally" ":" \token{suite}}
204+
\productioncont{["finally" ":" \token{suite}]}
205+
\production{try2_stmt}
206+
{"try" ":" \token{suite}}
207+
\productioncont{"finally" ":" \token{suite}}
208208
\end{productionlist}
209209

210-
There are two forms of \keyword{try} statement:
211-
\keyword{try}...\keyword{except} and
212-
\keyword{try}...\keyword{finally}. These forms cannot be mixed (but
213-
they can be nested in each other).
210+
\versionchanged[In previous versions of Python,
211+
\keyword{try}...\keyword{except}...\keyword{finally} did not work.
212+
\keyword{try}...\keyword{except} had to be nested in
213+
\keyword{try}...\keyword{finally}]{2.5}
214214

215-
The \keyword{try}...\keyword{except} form specifies one or more
216-
exception handlers
217-
(the \keyword{except} clauses). When no exception occurs in the
215+
The \keyword{except} clause(s) specify one or more exception handlers.
216+
When no exception occurs in the
218217
\keyword{try} clause, no exception handler is executed. When an
219218
exception occurs in the \keyword{try} suite, a search for an exception
220219
handler is started. This search inspects the except clauses in turn until
@@ -232,6 +231,8 @@ \section{The \keyword{try} statement\label{try}}
232231

233232
If no except clause matches the exception, the search for an exception
234233
handler continues in the surrounding code and on the invocation stack.
234+
\footnote{The exception is propogated to the invocation stack only if
235+
there is no \keyword{finally} clause that negates the exception.}
235236

236237
If the evaluation of an expression in the header of an except clause
237238
raises an exception, the original search for a handler is canceled
@@ -277,12 +278,13 @@ \section{The \keyword{try} statement\label{try}}
277278
\stindex{break}
278279
\stindex{continue}
279280

280-
The \keyword{try}...\keyword{finally} form specifies a `cleanup' handler. The
281-
\keyword{try} clause is executed. When no exception occurs, the
282-
\keyword{finally} clause is executed. When an exception occurs in the
283-
\keyword{try} clause, the exception is temporarily saved, the
284-
\keyword{finally} clause is executed, and then the saved exception is
285-
re-raised. If the \keyword{finally} clause raises another exception or
281+
If \keyword{finally} is present, it specifies a `cleanup' handler. The
282+
\keyword{try} clause is executed, including any \keyword{except} and
283+
\keyword{else} clauses. If an exception occurs in any of the clauses
284+
and is not handled, the exception is temporarily saved. The
285+
\keyword{finally} clause is executed. If there is a saved exception,
286+
it is re-raised at the end of the \keyword{finally} clause.
287+
If the \keyword{finally} clause raises another exception or
286288
executes a \keyword{return} or \keyword{break} statement, the saved
287289
exception is lost. A \keyword{continue} statement is illegal in the
288290
\keyword{finally} clause. (The reason is a problem with the current

Misc/NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Core and builtins
1414

1515
- Implementation of PEP 341 - Unification of try/except and try/finally.
1616
"except" clauses can now be written together with a "finally" clause in
17-
one try statement instead of two nested ones.
17+
one try statement instead of two nested ones. Patch #1355913.
1818

1919
- Bug #1379994: Builtin unicode_escape and raw_unicode_escape codec
2020
now encodes backslash correctly.

0 commit comments

Comments
 (0)