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

Skip to content

Commit 8823972

Browse files
committed
Documented class exceptions.
1 parent 305ed11 commit 8823972

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

Doc/ref/ref4.tex

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,33 @@ \section{Exceptions}
169169
When an exception is not handled at all, the interpreter terminates
170170
execution of the program, or returns to its interactive main loop.
171171

172-
Exceptions are identified by string objects. Two different string
173-
objects with the same value identify different exceptions.
172+
Exceptions are identified by string objects or class instances. Two
173+
different string objects with the same value identify different
174+
exceptions. An exception can be raised with a class instance. Such
175+
exceptions are caught by specifying an except clause that has the
176+
class name (or a base class) as the condition.
174177

175178
When an exception is raised, an object (maybe \verb@None@) is passed
176179
as the exception's ``parameter''; this object does not affect the
177180
selection of an exception handler, but is passed to the selected
178-
exception handler as additional information.
181+
exception handler as additional information. For exceptions raised
182+
with a class instance, the instance is passed as the ``parameter''.
183+
184+
For example:
185+
186+
\begin{verbatim}
187+
>>> class Error:
188+
... def __init__(self, msg): self.msg = msg
189+
...
190+
>>> class SpecificError(Error): pass
191+
...
192+
>>> try:
193+
... raise SpecificError('broken')
194+
... except Error, obj:
195+
... print obj.msg
196+
...
197+
broken
198+
\end{verbatim}
179199

180200
See also the description of the \verb@try@ and \verb@raise@
181201
statements.

Doc/ref4.tex

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,33 @@ \section{Exceptions}
169169
When an exception is not handled at all, the interpreter terminates
170170
execution of the program, or returns to its interactive main loop.
171171

172-
Exceptions are identified by string objects. Two different string
173-
objects with the same value identify different exceptions.
172+
Exceptions are identified by string objects or class instances. Two
173+
different string objects with the same value identify different
174+
exceptions. An exception can be raised with a class instance. Such
175+
exceptions are caught by specifying an except clause that has the
176+
class name (or a base class) as the condition.
174177

175178
When an exception is raised, an object (maybe \verb@None@) is passed
176179
as the exception's ``parameter''; this object does not affect the
177180
selection of an exception handler, but is passed to the selected
178-
exception handler as additional information.
181+
exception handler as additional information. For exceptions raised
182+
with a class instance, the instance is passed as the ``parameter''.
183+
184+
For example:
185+
186+
\begin{verbatim}
187+
>>> class Error:
188+
... def __init__(self, msg): self.msg = msg
189+
...
190+
>>> class SpecificError(Error): pass
191+
...
192+
>>> try:
193+
... raise SpecificError('broken')
194+
... except Error, obj:
195+
... print obj.msg
196+
...
197+
broken
198+
\end{verbatim}
179199

180200
See also the description of the \verb@try@ and \verb@raise@
181201
statements.

0 commit comments

Comments
 (0)