]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
added classes as exceptions
authorGuido van Rossum <guido@python.org>
Tue, 7 Feb 1995 14:37:17 +0000 (14:37 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 7 Feb 1995 14:37:17 +0000 (14:37 +0000)
Doc/ref/ref6.tex
Doc/ref/ref7.tex
Doc/ref6.tex
Doc/ref7.tex

index 70e1a68a6332db5c3ec558baf6e0ab4b93e3b932..f0f318fb71f7fb2f25bc6ab7b4c2754fd5b397da 100644 (file)
@@ -324,13 +324,20 @@ raise_stmt:     "raise" condition ["," condition]
 \end{verbatim}
 
 \verb@raise@ evaluates its first condition, which must yield
-a string object.  If there is a second condition, this is evaluated,
-else \verb@None@ is substituted.
+a string, class, or instance object.  If there is a second condition,
+this is evaluated, else \verb@None@ is substituted.  If the first
+condition is a class object, then the second condition must be an
+instance of that class or one of its derivatives.  If the first
+condition is an instance object, the second condition must be
+\verb@None@.
 \index{exception}
 \indexii{raising}{exception}
 
-It then raises the exception identified by the first object,
-with the second one (or \verb@None@) as its parameter.
+If the first object is a class or string, it then raises the exception
+identified by the first object, with the second one (or \verb@None@)
+as its parameter.  If the first object is an instance, it raises the
+exception identified by the class of the object, with the instance as
+its parameter.
 
 \section{The {\tt break} statement}
 \stindex{break}
index f099ae55432a45ee3a7d91614d39f66c3ae7d2a6..196215accaa1ed52b746032db261504fb9232d0e 100644 (file)
@@ -201,10 +201,11 @@ clause, if present, must be last; it matches any exception.  For an
 except clause with a condition, that condition is evaluated, and the
 clause matches the exception if the resulting object is ``compatible''
 with the exception.  An object is compatible with an exception if it
-is either the object that identifies the exception or it is a tuple
-containing an item that is compatible with the exception.  Note that
-the object identities must match, i.e. it must be the same object, not
-just an object with the same value.
+is either the object that identifies the exception, or (for exceptions
+that are classes) it is a base class of the exception, or it is a
+tuple containing an item that is compatible with the exception.  Note
+that the object identities must match, i.e. it must be the same
+object, not just an object with the same value.
 \kwindex{except}
 
 If no except clause matches the exception, the search for an exception
index 70e1a68a6332db5c3ec558baf6e0ab4b93e3b932..f0f318fb71f7fb2f25bc6ab7b4c2754fd5b397da 100644 (file)
@@ -324,13 +324,20 @@ raise_stmt:     "raise" condition ["," condition]
 \end{verbatim}
 
 \verb@raise@ evaluates its first condition, which must yield
-a string object.  If there is a second condition, this is evaluated,
-else \verb@None@ is substituted.
+a string, class, or instance object.  If there is a second condition,
+this is evaluated, else \verb@None@ is substituted.  If the first
+condition is a class object, then the second condition must be an
+instance of that class or one of its derivatives.  If the first
+condition is an instance object, the second condition must be
+\verb@None@.
 \index{exception}
 \indexii{raising}{exception}
 
-It then raises the exception identified by the first object,
-with the second one (or \verb@None@) as its parameter.
+If the first object is a class or string, it then raises the exception
+identified by the first object, with the second one (or \verb@None@)
+as its parameter.  If the first object is an instance, it raises the
+exception identified by the class of the object, with the instance as
+its parameter.
 
 \section{The {\tt break} statement}
 \stindex{break}
index f099ae55432a45ee3a7d91614d39f66c3ae7d2a6..196215accaa1ed52b746032db261504fb9232d0e 100644 (file)
@@ -201,10 +201,11 @@ clause, if present, must be last; it matches any exception.  For an
 except clause with a condition, that condition is evaluated, and the
 clause matches the exception if the resulting object is ``compatible''
 with the exception.  An object is compatible with an exception if it
-is either the object that identifies the exception or it is a tuple
-containing an item that is compatible with the exception.  Note that
-the object identities must match, i.e. it must be the same object, not
-just an object with the same value.
+is either the object that identifies the exception, or (for exceptions
+that are classes) it is a base class of the exception, or it is a
+tuple containing an item that is compatible with the exception.  Note
+that the object identities must match, i.e. it must be the same
+object, not just an object with the same value.
 \kwindex{except}
 
 If no except clause matches the exception, the search for an exception