diff options
author | Raymond Hettinger <python@rcn.com> | 2016-08-12 16:44:18 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-08-12 16:44:18 (GMT) |
commit | 87fe473edc933ce8a3c886efff8e6389f90b3e57 (patch) | |
tree | 7afee922522fa3c9a4f10279e3e71a5e0650dc0f /Doc/tutorial | |
parent | c57e4d16eab07449bbda598a9272e4eb03f60814 (diff) | |
parent | 7f65af3d2d11927141ba6c952da5b7a674452ff1 (diff) | |
download | cpython-87fe473edc933ce8a3c886efff8e6389f90b3e57.zip cpython-87fe473edc933ce8a3c886efff8e6389f90b3e57.tar.gz cpython-87fe473edc933ce8a3c886efff8e6389f90b3e57.tar.bz2 |
merge
Diffstat (limited to 'Doc/tutorial')
-rw-r--r-- | Doc/tutorial/errors.rst | 24 |
1 files changed, 1 insertions, 23 deletions
diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 4195c7e..ddb69ca 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -244,29 +244,7 @@ User-defined Exceptions Programs may name their own exceptions by creating a new exception class (see :ref:`tut-classes` for more about Python classes). Exceptions should typically -be derived from the :exc:`Exception` class, either directly or indirectly. For -example:: - - >>> class MyError(Exception): - ... def __init__(self, value): - ... self.value = value - ... def __str__(self): - ... return repr(self.value) - ... - >>> try: - ... raise MyError(2*2) - ... except MyError as e: - ... print('My exception occurred, value:', e.value) - ... - My exception occurred, value: 4 - >>> raise MyError('oops!') - Traceback (most recent call last): - File "<stdin>", line 1, in ? - __main__.MyError: 'oops!' - -In this example, the default :meth:`__init__` of :class:`Exception` has been -overridden. The new behavior simply creates the *value* attribute. This -replaces the default behavior of creating the *args* attribute. +be derived from the :exc:`Exception` class, either directly or indirectly. Exception classes can be defined which do anything any other class can do, but are usually kept simple, often only offering a number of attributes that allow |