[Python-checkins] CVS: python/dist/src/Doc/tut tut.tex,1.106,1.107
Fred Drake
python-dev@python.org
Mon, 17 Apr 2000 10:56:34 -0400
Update of /projects/cvsroot/python/dist/src/Doc/tut
In directory seahag.cnri.reston.va.us:/home/fdrake/projects/python/Doc/tut
Modified Files:
tut.tex
Log Message:
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>.
Index: tut.tex
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.106
retrieving revision 1.107
diff -C2 -r1.106 -r1.107
*** tut.tex 2000/04/06 14:17:03 1.106
--- tut.tex 2000/04/17 14:56:31 1.107
***************
*** 2997,3003 ****
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:
\begin{verbatim}
--- 2997,3003 ----
The \keyword{try} \ldots\ \keyword{except} statement has an optional
! \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}
***************
*** 3011,3014 ****
--- 3011,3019 ----
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.