Re: change an exception's message and re-raise it

2010-01-01 Thread Phlip
On Dec 31 2009, 4:30 pm, Steven D'Aprano wrote: > For the record you can get the exception type from type(e): > > raise type(e)("whatever you want") > > but that creates a new exception, not re-raising the old one. Except if a type constructs with some other number of arguments, apparently... --

Re: change an exception's message and re-raise it

2010-01-01 Thread Phlip
On Dec 31 2009, 4:30 pm, Steven D'Aprano wrote: > ...     1/0 > ... except ZeroDivisionError, e: > ...     e.args = e.args + ('fe', 'fi', 'fo', 'fum') > ...     raise When I added print e.args it showed the old args. Maybe I was trying too hard - this is why I said e seemed locked or something.

Re: change an exception's message and re-raise it

2009-12-31 Thread Alan G Isaac
On 12/31/2009 7:30 PM, Steven D'Aprano wrote: The message attribute is deprecated from Python 2.6 and will print a warning if you try to use it. http://bugs.python.org/issue6844 fwiw, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: change an exception's message and re-raise it

2009-12-31 Thread Steven D'Aprano
On Thu, 31 Dec 2009 12:18:42 -0800, Phlip wrote: > Pythonistas: > > I need to do this: > > try: > deep_arcane_layer() > except e: > e.message = 'the deep arcane layer says: ' + e.message > raise e Use e.args, not e.message. The message attribute is deprecated from Python 2.6 a

Re: change an exception's message and re-raise it

2009-12-31 Thread Cameron Simpson
On 31Dec2009 12:18, Phlip wrote: | Pythonistas: | | I need to do this: | | try: | deep_arcane_layer() | except e: | e.message = 'the deep arcane layer says: ' + e.message | raise e | | The point is I need to augment that layer's exceptions with extra | information that I know a

Re: change an exception's message and re-raise it

2009-12-31 Thread Stephen Hansen
On Thu, Dec 31, 2009 at 12:18 PM, Phlip wrote: > The point is I need to augment that layer's exceptions with extra > information that I know about that layer. > > I would take advantage of the fact that exceptions are real, full-blown objects, and not just treat them as something that holds a str

change an exception's message and re-raise it

2009-12-31 Thread Phlip
Pythonistas: I need to do this: try: deep_arcane_layer() except e: e.message = 'the deep arcane layer says: ' + e.message raise e The point is I need to augment that layer's exceptions with extra information that I know about that layer. I naturally cannot use the argless versi