@@ -120,6 +120,33 @@ name multiple exceptions as a parenthesized tuple, for example::
120120 ... except (RuntimeError, TypeError, NameError):
121121 ... pass
122122
123+ A class in an :keyword: `except ` clause is compatible with an exception if it is
124+ the same class or a base class thereof (but not the other way around --- an
125+ except clause listing a derived class is not compatible with a base class). For
126+ example, the following code will print B, C, D in that order::
127+
128+ class B(Exception):
129+ pass
130+
131+ class C(B):
132+ pass
133+
134+ class D(C):
135+ pass
136+
137+ for cls in [B, C, D]:
138+ try:
139+ raise cls()
140+ except D:
141+ print("D")
142+ except C:
143+ print("C")
144+ except B:
145+ print("B")
146+
147+ Note that if the except clauses were reversed (with ``except B `` first), it
148+ would have printed B, B, B --- the first matching except clause is triggered.
149+
123150The last except clause may omit the exception name(s), to serve as a wildcard.
124151Use this with extreme caution, since it is easy to mask a real programming error
125152in this way! It can also be used to print an error message and then re-raise
@@ -219,7 +246,10 @@ exception to occur. For example::
219246
220247The sole argument to :keyword: `raise ` indicates the exception to be raised.
221248This must be either an exception instance or an exception class (a class that
222- derives from :class: `Exception `).
249+ derives from :class: `Exception `). If an exception class is passed, it will
250+ be implicitly instantiated by calling its constructor with no arguments::
251+
252+ raise ValueError # shorthand for 'raise ValueError()'
223253
224254If you need to determine whether an exception was raised but don't intend to
225255handle it, a simpler form of the :keyword: `raise ` statement allows you to
0 commit comments