Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87fe473

Browse files
committed
merge
2 parents c57e4d1 + 7f65af3 commit 87fe473

1 file changed

Lines changed: 1 addition & 23 deletions

File tree

Doc/tutorial/errors.rst

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,7 @@ User-defined Exceptions
244244

245245
Programs 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

271249
Exception classes can be defined which do anything any other class can do, but
272250
are usually kept simple, often only offering a number of attributes that allow

0 commit comments

Comments
 (0)