diff options
author | Fred Drake <fdrake@acm.org> | 2000-04-17 14:56:31 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-04-17 14:56:31 (GMT) |
commit | e99d1dbc7465d983a2ae99eb0f439ba830f45ff8 (patch) | |
tree | 7ec728d34275c66ec96fe158118a5883f026de7f /Doc | |
parent | eacdea85725a763197eca34bc57da3e5d399282f (diff) | |
download | cpython-e99d1dbc7465d983a2ae99eb0f439ba830f45ff8.zip cpython-e99d1dbc7465d983a2ae99eb0f439ba830f45ff8.tar.gz cpython-e99d1dbc7465d983a2ae99eb0f439ba830f45ff8.tar.bz2 |
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 <msimcich@accesstools.com>.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/tut/tut.tex | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index daae169..bdb5556 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -2996,9 +2996,9 @@ except: \end{verbatim} The \keyword{try} \ldots\ \keyword{except} statement has an optional -\emph{else clause}, which must follow all except clauses. It is -useful to place code that must be executed if the try clause does not -raise an exception. For example: +\emph{else clause}, which, when present, must follow all except +clauses. It is useful for code that must be executed if the try +clause does not raise an exception. For example: \begin{verbatim} for arg in sys.argv[1:]: @@ -3011,6 +3011,11 @@ for arg in sys.argv[1:]: f.close() \end{verbatim} +The use of the \keyword{else} clause is better than adding additional +code to the \keyword{try} clause because it avoids accidentally +catching an exception that wasn't raised by the code being protected +by the \keyword{try} \ldots\ \keyword{except} statement. + When an exception occurs, it may have an associated value, also known as the exceptions's \emph{argument}. |