Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8823972c
Commit
8823972c
authored
Aug 19, 1996
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documented class exceptions.
parent
305ed11a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
6 deletions
+46
-6
Doc/ref/ref4.tex
Doc/ref/ref4.tex
+23
-3
Doc/ref4.tex
Doc/ref4.tex
+23
-3
No files found.
Doc/ref/ref4.tex
View file @
8823972c
...
...
@@ -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.
Doc/ref4.tex
View file @
8823972c
...
...
@@ -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.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment