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

Skip to content

Commit a2a9888

Browse files
author
Michael W. Hudson
committed
Updates to the exceptions documentation (this is my patch #1156102).
1 parent c72dd38 commit a2a9888

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

Doc/ref/ref4.tex

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,20 @@ \section{Exceptions \label{exceptions}}
182182
\exception{SystemExit}\withsubitem{(built-in
183183
exception)}{\ttindex{SystemExit}}.
184184

185-
Exceptions are identified by class instances.
186-
Selection of a matching except clause is based on object identity.
187-
The \keyword{except} clause must reference the same class or a base
188-
class of it.
189-
190-
When an exception is raised, an object (maybe \code{None}) is passed
191-
as the exception's \emph{value}; this object does not affect the
192-
selection of an exception handler, but is passed to the selected
193-
exception handler as additional information. For class exceptions,
194-
this object must be an instance of the exception class being raised.
185+
Exceptions are identified by class instances. The \keyword{except}
186+
clause is selected depending on the class of the instance: it must
187+
reference the class of the instance or a base class thereof. The
188+
instance can be received by the handler and can carry additional
189+
information about the exceptional condition.
190+
191+
Exceptions can also be identified by strings, in which case the
192+
\keyword{except} clause is selected by object identity. An arbitrary
193+
value can be raised along with the identifying string which can be
194+
passed to the handler.
195+
196+
\deprecated{2.5}{String exceptions should not be used in new code.
197+
They will not be supported in a future version of Python. Old code
198+
should be rewritten to use class exceptions instead.}
195199

196200
\begin{notice}[warning]
197201
Messages to exceptions are not part of the Python API. Their contents may

Doc/ref/ref7.tex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ \section{The \keyword{try} statement\label{try}}
223223
except clause with an expression, that expression is evaluated, and the
224224
clause matches the exception if the resulting object is ``compatible''
225225
with the exception. An object is compatible with an exception if it
226-
is either the object that identifies the exception, or (for exceptions
227-
that are classes) it is a base class of the exception, or it is a
228-
tuple containing an item that is compatible with the exception. Note
229-
that the object identities must match, i.e. it must be the same
230-
object, not just an object with the same value.
226+
is the class or a base class of the exception object, a tuple
227+
containing an item compatible with the exception, or, in the
228+
(deprecated) case of string exceptions, is the raised string itself
229+
(note that the object identities must match, i.e. it must be the same
230+
string object, not just a string with the same value).
231231
\kwindex{except}
232232

233233
If no except clause matches the exception, the search for an exception
@@ -239,14 +239,14 @@ \section{The \keyword{try} statement\label{try}}
239239
on the call stack (it is treated as if the entire \keyword{try} statement
240240
raised the exception).
241241

242-
When a matching except clause is found, the exception's parameter is
243-
assigned to the target specified in that except clause, if present,
244-
and the except clause's suite is executed. All except clauses must
245-
have an executable block. When the end of this block
246-
is reached, execution continues normally after the entire try
247-
statement. (This means that if two nested handlers exist for the same
248-
exception, and the exception occurs in the try clause of the inner
249-
handler, the outer handler will not handle the exception.)
242+
When a matching except clause is found, the exception is assigned to
243+
the target specified in that except clause, if present, and the except
244+
clause's suite is executed. All except clauses must have an
245+
executable block. When the end of this block is reached, execution
246+
continues normally after the entire try statement. (This means that
247+
if two nested handlers exist for the same exception, and the exception
248+
occurs in the try clause of the inner handler, the outer handler will
249+
not handle the exception.)
250250

251251
Before an except clause's suite is executed, details about the
252252
exception are assigned to three variables in the

0 commit comments

Comments
 (0)