Commit 7d4f8fda authored by Georg Brandl's avatar Georg Brandl

#6777: dont discourage usage of Exception.args or promote usage of Exception.message.

parent 601ee7f8
...@@ -165,14 +165,11 @@ exception type. ...@@ -165,14 +165,11 @@ exception type.
The except clause may specify a variable after the exception name (or tuple). 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 The variable is bound to an exception instance with the arguments stored in
``instance.args``. For convenience, the exception instance defines ``instance.args``. For convenience, the exception instance defines
:meth:`__getitem__` and :meth:`__str__` so the arguments can be accessed or :meth:`__str__` so the arguments can be printed directly without having to
printed directly without having to reference ``.args``. reference ``.args``.
But use of ``.args`` is discouraged. Instead, the preferred use is to pass a One may also instantiate an exception first before raising it and add any
single argument to an exception (which can be a tuple if multiple arguments are attributes to it as desired. ::
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. ::
>>> try: >>> try:
... raise Exception('spam', 'eggs') ... raise Exception('spam', 'eggs')
...@@ -288,28 +285,28 @@ to create specific exception classes for different error conditions:: ...@@ -288,28 +285,28 @@ to create specific exception classes for different error conditions::
"""Exception raised for errors in the input. """Exception raised for errors in the input.
Attributes: Attributes:
expression -- input expression in which the error occurred expr -- input expression in which the error occurred
message -- explanation of the error msg -- explanation of the error
""" """
def __init__(self, expression, message): def __init__(self, expr, msg):
self.expression = expression self.expr = expr
self.message = message self.msg = msg
class TransitionError(Error): class TransitionError(Error):
"""Raised when an operation attempts a state transition that's not """Raised when an operation attempts a state transition that's not
allowed. allowed.
Attributes: Attributes:
previous -- state at beginning of transition prev -- state at beginning of transition
next -- attempted new state 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): def __init__(self, prev, next, msg):
self.previous = previous self.prev = prev
self.next = next self.next = next
self.message = message self.msg = msg
Most exceptions are defined with names that end in "Error," similar to the Most exceptions are defined with names that end in "Error," similar to the
naming of the standard exceptions. naming of the standard exceptions.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment