Kaydet (Commit) eb8b0d20 authored tarafından Guido van Rossum's avatar Guido van Rossum

added classes as exceptions

üst 626c1e78
......@@ -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}
......
......@@ -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
......
......@@ -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}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment