diff options
author | Guido van Rossum <guido@python.org> | 1996-08-19 23:00:03 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-08-19 23:00:03 (GMT) |
commit | 8823972cea8d955fb8a5511a30eb7db15f6fc467 (patch) | |
tree | a312c50fc37d40e19bcb5cce8b04fd9b7b1191bd /Doc/ref | |
parent | 305ed11a74bbdf1de279232c4c64a65ec3e0f92b (diff) | |
download | cpython-8823972cea8d955fb8a5511a30eb7db15f6fc467.zip cpython-8823972cea8d955fb8a5511a30eb7db15f6fc467.tar.gz cpython-8823972cea8d955fb8a5511a30eb7db15f6fc467.tar.bz2 |
Documented class exceptions.
Diffstat (limited to 'Doc/ref')
-rw-r--r-- | Doc/ref/ref4.tex | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/Doc/ref/ref4.tex b/Doc/ref/ref4.tex index ed621c4..4b4d522 100644 --- a/Doc/ref/ref4.tex +++ b/Doc/ref/ref4.tex @@ -169,13 +169,33 @@ code from the top). When an exception is not handled at all, the interpreter terminates execution of the program, or returns to its interactive main loop. -Exceptions are identified by string objects. Two different string -objects with the same value identify different exceptions. +Exceptions are identified by string objects or class instances. Two +different string objects with the same value identify different +exceptions. An exception can be raised with a class instance. Such +exceptions are caught by specifying an except clause that has the +class name (or a base class) as the condition. When an exception is raised, an object (maybe \verb@None@) is passed as the exception's ``parameter''; this object does not affect the selection of an exception handler, but is passed to the selected -exception handler as additional information. +exception handler as additional information. For exceptions raised +with a class instance, the instance is passed as the ``parameter''. + +For example: + +\begin{verbatim} +>>> class Error: +... def __init__(self, msg): self.msg = msg +... +>>> class SpecificError(Error): pass +... +>>> try: +... raise SpecificError('broken') +... except Error, obj: +... print obj.msg +... +broken +\end{verbatim} See also the description of the \verb@try@ and \verb@raise@ statements. |