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

Skip to content

Commit 0068e2c

Browse files
committed
New exception catching syntax.
1 parent 105f60e commit 0068e2c

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

Doc/reference/compound_stmts.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ for a group of statements:
219219
.. productionlist::
220220
try_stmt: try1_stmt | try2_stmt
221221
try1_stmt: "try" ":" `suite`
222-
: ("except" [`expression` ["," `target`]] ":" `suite`)+
222+
: ("except" [`expression` ["as" `target`]] ":" `suite`)+
223223
: ["else" ":" `suite`]
224224
: ["finally" ":" `suite`]
225225
try2_stmt: "try" ":" `suite`
226226
: "finally" ":" `suite`
227227

228-
The :keyword:`except` clause(s) specify one or more exception handlers. When no
228+
The :keyword:`except` clause(s) specify one or more exception handlers. When no
229229
exception occurs in the :keyword:`try` clause, no exception handler is executed.
230230
When an exception occurs in the :keyword:`try` suite, a search for an exception
231231
handler is started. This search inspects the except clauses in turn until one
@@ -245,12 +245,12 @@ the new exception in the surrounding code and on the call stack (it is treated
245245
as if the entire :keyword:`try` statement raised the exception).
246246

247247
When a matching except clause is found, the exception is assigned to the target
248-
specified in that except clause, if present, and the except clause's suite is
249-
executed. All except clauses must have an executable block. When the end of
250-
this block is reached, execution continues normally after the entire try
251-
statement. (This means that if two nested handlers exist for the same
252-
exception, and the exception occurs in the try clause of the inner handler, the
253-
outer handler will not handle the exception.)
248+
specified after the ``as`` keyword in that except clause, if present, and the
249+
except clause's suite is executed. All except clauses must have an executable
250+
block. When the end of this block is reached, execution continues normally
251+
after the entire try statement. (This means that if two nested handlers exist
252+
for the same exception, and the exception occurs in the try clause of the inner
253+
handler, the outer handler will not handle the exception.)
254254

255255
.. index::
256256
module: sys
@@ -545,4 +545,3 @@ instance variables with different implementation details.
545545
.. [#] Currently, control "flows off the end" except in the case of an exception or the
546546
execution of a :keyword:`return`, :keyword:`continue`, or :keyword:`break`
547547
statement.
548-

0 commit comments

Comments
 (0)