diff options
| author | Berker Peksag <berker.peksag@gmail.com> | 2016-11-06 18:15:01 (GMT) |
|---|---|---|
| committer | Berker Peksag <berker.peksag@gmail.com> | 2016-11-06 18:15:01 (GMT) |
| commit | cea632ece5f127f10f6b831fc8dfc72acab181d7 (patch) | |
| tree | 38af263b9146a34452987f501b02ea77c6be4210 /Doc/tutorial/classes.rst | |
| parent | 24411f8a8daace4ebf8abd41091b681160b4fb89 (diff) | |
| download | cpython-cea632ece5f127f10f6b831fc8dfc72acab181d7.zip cpython-cea632ece5f127f10f6b831fc8dfc72acab181d7.tar.gz cpython-cea632ece5f127f10f6b831fc8dfc72acab181d7.tar.bz2 | |
Issue #21864: Remove outdated section about exceptions from the tutorial
Move the still relevant parts of it to the previous
chapter, "Errors and Exceptions".
Diffstat (limited to 'Doc/tutorial/classes.rst')
| -rw-r--r-- | Doc/tutorial/classes.rst | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index 03b77e0..75c79d2 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -744,55 +744,6 @@ object with the method :meth:`m`, and ``m.__func__`` is the function object corresponding to the method. -.. _tut-exceptionclasses: - -Exceptions Are Classes Too -========================== - -User-defined exceptions are identified by classes as well. Using this mechanism -it is possible to create extensible hierarchies of exceptions. - -There are two new valid (semantic) forms for the :keyword:`raise` statement:: - - raise Class - - raise Instance - -In the first form, ``Class`` must be an instance of :class:`type` or of a -class derived from it. The first form is a shorthand for:: - - raise Class() - -A class in an :keyword:`except` clause is compatible with an exception if it is -the same class or a base class thereof (but not the other way around --- an -except clause listing a derived class is not compatible with a base class). For -example, the following code will print B, C, D in that order:: - - class B(Exception): - pass - class C(B): - pass - class D(C): - pass - - for cls in [B, C, D]: - try: - raise cls() - except D: - print("D") - except C: - print("C") - except B: - print("B") - -Note that if the except clauses were reversed (with ``except B`` first), it -would have printed B, B, B --- the first matching except clause is triggered. - -When an error message is printed for an unhandled exception, the exception's -class name is printed, then a colon and a space, and finally the instance -converted to a string using the built-in function :func:`str`. - - .. _tut-iterators: Iterators |
