A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-April/052651.html below:

[Python-Dev] args attribute of Exception objects

[Python-Dev] args attribute of Exception objects [Python-Dev] args attribute of Exception objectsRaymond Hettinger python at rcn.com
Tue Apr 12 14:03:50 CEST 2005
[Sébastien de Menten]
>  2) Could this be changed to .args more in line with:
>     a) first example: e.args = ('foo', "NameError: name 'foo' is not
> defined")
>     b) second example: e.args = (4, 'foo', "'int' object has no
attribute
> 'foo'",)
>   the message of the string can even be retrieved with str(e) so it is
> also
> redundant.

Something like this ought to be explored at some point.  It would
certainly improve the exception API to be able to get references to the
objects without parsing strings.

The balancing forces are backwards compatibility and a need to keep the
exception mechanism as lightweight as possible.

Please log a feature request on SF.  Note that the idea is only for
making builtin exceptions more informative.  User defined exceptions can
already attach arbitrary objects:

>>> class Boom(Exception):
        pass

>>> x = 10
>>> if x != 5:
        raise Boom("Value must be a five", x)

Traceback (most recent call last):
  File "<pyshell#12>", line 2, in -toplevel-
    raise Boom("Value must be a five", x)
Boom: ('Value must be a five', 10)


Raymond Hettinger
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4