@@ -244,29 +244,7 @@ User-defined Exceptions
244244
245245Programs may name their own exceptions by creating a new exception class (see
246246:ref: `tut-classes ` for more about Python classes). Exceptions should typically
247- be derived from the :exc: `Exception ` class, either directly or indirectly. For
248- example::
249-
250- >>> class MyError(Exception):
251- ... def __init__(self, value):
252- ... self.value = value
253- ... def __str__(self):
254- ... return repr(self.value)
255- ...
256- >>> try:
257- ... raise MyError(2*2)
258- ... except MyError as e:
259- ... print('My exception occurred, value:', e.value)
260- ...
261- My exception occurred, value: 4
262- >>> raise MyError('oops!')
263- Traceback (most recent call last):
264- File "<stdin>", line 1, in ?
265- __main__.MyError: 'oops!'
266-
267- In this example, the default :meth: `__init__ ` of :class: `Exception ` has been
268- overridden. The new behavior simply creates the *value * attribute. This
269- replaces the default behavior of creating the *args * attribute.
247+ be derived from the :exc: `Exception ` class, either directly or indirectly.
270248
271249Exception classes can be defined which do anything any other class can do, but
272250are usually kept simple, often only offering a number of attributes that allow
0 commit comments