En Mon, 16 Jul 2007 13:50:50 -0300, fumanchu <[EMAIL PROTECTED]> escribió:
> On Jul 15, 2:55 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
>> Here is a simple solution, but it depends
>> on the existence of the args attribute that
>> "will eventually be deprecated" according
>> to the docs
>
On Jul 15, 2:55 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Here is a simple solution, but it depends
> on the existence of the args attribute that
> "will eventually be deprecated" according
> to the docs
If you don't mind using .args, then the solution is usually as simple
as:
try:
Christoph Zwerschke wrote:
> Here is a simple solution, but it depends on the existence of the args
> attribute that "will eventually be deprecated" according to the docs:
Just found another amazingly simple solution that does neither use teh
.args (docs: "will eventually be deprecated") attribu
Christoph Zwerschke wrote:
> Here is a simple solution, but it depends on the existence of the args
> attribute that "will eventually be deprecated" according to the docs:
Ok, here is another solution that does not depend on args:
def PoliteException(e):
E = e.__class__
class PoliteExc
Christoph Zwerschke wrote:
> But my __getattr__ solution does not work either, since the attributes
> are set to None when initialized, so __getattr__ is never called.
Here is a simple solution, but it depends on the existence of the args
attribute that "will eventually be deprecated" according
samwyse wrote:
> NewStyle.__name__ = old.__class__.__name__
Simple, but that does the trick!
> new.__dict__ = old.__dict__.copy()
Unfortunately, that does not work, since the attributes are not
writeable and thus do not appear in __dict__.
But my __getattr__ solution does not work either, si
On Jul 13, 12:45 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> samwyse wrote:
> > TypeError: __class__ must be set to a class
>
> > Excpt ceratinly appears to be a class. Does anyone smarter than me
> > know what's going on here?
>
> Not that I want to appear smarter, but I think the proble
samwyse wrote:
> TypeError: __class__ must be set to a class
>
> Excpt ceratinly appears to be a class. Does anyone smarter than me
> know what's going on here?
Not that I want to appear smarter, but I think the problem here is that
exceptions are new-style classes now, whereas Empty is an old-
On Jul 12, 6:31 am, samwyse <[EMAIL PROTECTED]> wrote:
> On Jul 8, 8:50 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
>
> > With Py 2.5 I get:
>
> > new.__class__ = old.__class__
> > TypeError: __class__ must be set to a class
Hmmm, under Python 2.4.X, printing repr(old.__class__) gives
On Jul 8, 8:50 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Did you run this?
> With Py < 2.5 I get a syntax error, and with Py 2.5 I get:
>
> new.__class__ = old.__class__
> TypeError: __class__ must be set to a class
>
> -- Chris
Damn, I'd have sworn I ran the final copy that I post
samwyse wrote:
> def test(code):
> try:
> code()
> except Exception, e:
> try:
> raise e.__class__, str(e) + ", sorry!"
> except TypeError:
> raise SorryFactory(e)()
Ok, you're suggestig the naive approach if it works and the factory
approach I came up with last as a f
Did you run this?
With Py < 2.5 I get a syntax error, and with Py 2.5 I get:
new.__class__ = old.__class__
TypeError: __class__ must be set to a class
-- Chris
--
http://mail.python.org/mailman/listinfo/python-list
On Jul 5, 8:53 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> What is the best way to re-raise any exception with a message
> supplemented with additional information (e.g. line number in a
> template)? Let's say for simplicity I just want to add "sorry" to every
> exception message.
OK, thi
On Jul 7, 4:13 pm, samwyse <[EMAIL PROTECTED]> wrote:
> On Jul 5, 8:53 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
>
> > What is the best way to re-raise any exception with a message
> > supplemented with additional information (e.g. line number in a
> > template)?
[...]
> That leaves the is
On Jul 5, 8:53 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> What is the best way to re-raise any exception with a message
> supplemented with additional information (e.g. line number in a
> template)? Let's say for simplicity I just want to add "sorry" to every
> exception message. My naive
Gerard Flanagan wrote:
> Would a decorator work here?
Depends on how you want to use that functionality. In my use case I only
need to catch the excpetion once.
Note that in your code the exception has not the right type which is
what I targeted in my last posting. I.e. the following will raise
On Jul 6, 12:18 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Sorry for the soliloquy, but what I am really using is the following so
> that the re-raised excpetion has the same type:
>
> def PoliteException(e):
> class PoliteException(e.__class__):
> def __init__(self, e):
>
On 2007-07-06, Alex Popescu <[EMAIL PROTECTED]> wrote:
> On Jul 6, 4:20 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
>> Alex Popescu wrote:
>> > Probably the simplest solution would be to create a new exception and
>> > wrapping the old one and the additional info. Unfortunately, this
>> > ma
On Jul 6, 4:20 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Alex Popescu wrote:
> > Probably the simplest solution would be to create a new exception and
> > wrapping the old one and the additional info. Unfortunately, this
> > may have a huge impact on 3rd party code that was catching the
On Jul 6, 4:20 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Alex Popescu wrote:
>
--
http://mail.python.org/mailman/listinfo/python-list
Alex Popescu wrote:
> Probably the simplest solution would be to create a new exception and
> wrapping the old one and the additional info. Unfortunately, this
> may have a huge impact on 3rd party code that was catching the
> original exception. So, I think you should create an utility
> factor
Sorry for the soliloquy, but what I am really using is the following so
that the re-raised excpetion has the same type:
def PoliteException(e):
class PoliteException(e.__class__):
def __init__(self, e):
self._e = e
def __getattr__(self, name):
retu
On Jul 6, 12:21 am, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Kay Schluehr wrote:
> > If you are sure that the exception isn't caught on another level just
> > use the following showtraceback() function, manipulate it's output
> > slightly and terminate your program with sys.exit()
>
> That'
Seems that no simple solution exists,
so for now, I will be using something like this:
class PoliteException(Exception):
def __init__(self, e):
self._e = e
def __getattr__(self, name):
return getattr(self._e, name)
def __str__(self):
if isinstance(self._e,
Kay Schluehr wrote:
> If you are sure that the exception isn't caught on another level just
> use the following showtraceback() function, manipulate it's output
> slightly and terminate your program with sys.exit()
That's what I want to avoid. In my case the error is displayed and
evaluated in a
On Jul 5, 3:53 pm, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> What is the best way to re-raise any exception with a message
> supplemented with additional information (e.g. line number in a
> template)? Let's say for simplicity I just want to add "sorry" to every
> exception message. My naive
On 2007-07-05, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> You may need the traceback module to get at the error message, if
>> trying to read e.message can fail.
>>
>> Something like this mess here: ;)
>>
>>...
>>except Exception, e:
>> etype, evalue, etb
Neil Cerutti wrote:
> You may need the traceback module to get at the error message, if
> trying to read e.message can fail.
>
> Something like this mess here: ;)
>
>...
>except Exception, e:
> etype, evalue, etb = sys.exc_info()
> ex = traceback.format_exception_only(etype, eva
On 2007-07-05, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> The documentation for BaseException contains something that might
>> be relevant:
>>
>>[...] If more data needs to be attached to the exception,
>>attach it through arbitrary attributes on the instance.
Neil Cerutti wrote:
> The documentation for BaseException contains something that might
> be relevant:
>
>[...] If more data needs to be attached to the exception,
>attach it through arbitrary attributes on the instance. All
>
> Users could get at the extra info you attached, but it wouldn
On 2007-07-05, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
> Thomas Heller wrote:
>> I have the impression that you do NOT want to change the
>> exceptions, instead you want to print the traceback in a
>> customized way. But I may be wrong...
>
> No, I really want to modify the exception, suppl
Thomas Heller wrote:
> I have the impression that you do NOT want to change the exceptions,
> instead you want to print the traceback in a customized way. But I may be
> wrong...
No, I really want to modify the exception, supplementing its message
with additional information about the state of
Christoph Zwerschke schrieb:
> What is the best way to re-raise any exception with a message
> supplemented with additional information (e.g. line number in a
> template)?
I have the impression that you do NOT want to change the exceptions,
instead you want to print the traceback in a customized
What is the best way to re-raise any exception with a message
supplemented with additional information (e.g. line number in a
template)? Let's say for simplicity I just want to add "sorry" to every
exception message. My naive solution was this:
try:
...
except Exception, e:
raise e.__
34 matches
Mail list logo