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

Skip to content

Commit e99d1db

Browse files
committed
Clarify the description of the else clause for try/except, and add an
explanation of why you'd want to use it. Based on a question from Michael Simcich <[email protected]>.
1 parent eacdea8 commit e99d1db

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Doc/tut/tut.tex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,9 +2996,9 @@ \section{Handling Exceptions \label{handling}}
29962996
\end{verbatim}
29972997
29982998
The \keyword{try} \ldots\ \keyword{except} statement has an optional
2999-
\emph{else clause}, which must follow all except clauses. It is
3000-
useful to place code that must be executed if the try clause does not
3001-
raise an exception. For example:
2999+
\emph{else clause}, which, when present, must follow all except
3000+
clauses. It is useful for code that must be executed if the try
3001+
clause does not raise an exception. For example:
30023002
30033003
\begin{verbatim}
30043004
for arg in sys.argv[1:]:
@@ -3011,6 +3011,11 @@ \section{Handling Exceptions \label{handling}}
30113011
f.close()
30123012
\end{verbatim}
30133013
3014+
The use of the \keyword{else} clause is better than adding additional
3015+
code to the \keyword{try} clause because it avoids accidentally
3016+
catching an exception that wasn't raised by the code being protected
3017+
by the \keyword{try} \ldots\ \keyword{except} statement.
3018+
30143019
30153020
When an exception occurs, it may have an associated value, also known as
30163021
the exceptions's \emph{argument}.

0 commit comments

Comments
 (0)