summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-09-04 11:32:18 (GMT)
committerGeorg Brandl <georg@python.org>2009-09-04 11:32:18 (GMT)
commit7d4f8fda4930219754642b0776a49759ac5716a7 (patch)
tree5e81aa0e3d7936fd18b77ed3f22ee39488833774 /Doc/tutorial
parent601ee7f8470bcad409debcdaa053ce456bc158eb (diff)
downloadcpython-7d4f8fda4930219754642b0776a49759ac5716a7.zip
cpython-7d4f8fda4930219754642b0776a49759ac5716a7.tar.gz
cpython-7d4f8fda4930219754642b0776a49759ac5716a7.tar.bz2
#6777: dont discourage usage of Exception.args or promote usage of Exception.message.
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/errors.rst31
1 files changed, 14 insertions, 17 deletions
diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst
index d547ef7..300cbd1 100644
--- a/Doc/tutorial/errors.rst
+++ b/Doc/tutorial/errors.rst
@@ -165,14 +165,11 @@ exception type.
The except clause may specify a variable after the exception name (or tuple).
The variable is bound to an exception instance with the arguments stored in
``instance.args``. For convenience, the exception instance defines
-:meth:`__getitem__` and :meth:`__str__` so the arguments can be accessed or
-printed directly without having to reference ``.args``.
+:meth:`__str__` so the arguments can be printed directly without having to
+reference ``.args``.
-But use of ``.args`` is discouraged. Instead, the preferred use is to pass a
-single argument to an exception (which can be a tuple if multiple arguments are
-needed) and have it bound to the ``message`` attribute. One may also
-instantiate an exception first before raising it and add any attributes to it as
-desired. ::
+One may also instantiate an exception first before raising it and add any
+attributes to it as desired. ::
>>> try:
... raise Exception('spam', 'eggs')
@@ -288,28 +285,28 @@ to create specific exception classes for different error conditions::
"""Exception raised for errors in the input.
Attributes:
- expression -- input expression in which the error occurred
- message -- explanation of the error
+ expr -- input expression in which the error occurred
+ msg -- explanation of the error
"""
- def __init__(self, expression, message):
- self.expression = expression
- self.message = message
+ def __init__(self, expr, msg):
+ self.expr = expr
+ self.msg = msg
class TransitionError(Error):
"""Raised when an operation attempts a state transition that's not
allowed.
Attributes:
- previous -- state at beginning of transition
+ prev -- state at beginning of transition
next -- attempted new state
- message -- explanation of why the specific transition is not allowed
+ msg -- explanation of why the specific transition is not allowed
"""
- def __init__(self, previous, next, message):
- self.previous = previous
+ def __init__(self, prev, next, msg):
+ self.prev = prev
self.next = next
- self.message = message
+ self.msg = msg
Most exceptions are defined with names that end in "Error," similar to the
naming of the standard exceptions.