Re-raising exceptions with modified message

Christoph Zwerschke cito at online.de
Fri Jul 13 01:45:20 EDT 2007


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-style 
class. But even if you define Empty as a new-style class, it will not 
work, you get:

TypeError: __class__ assignment: only for heap types

This tells us that we cannot change the attributes of a built-in 
exception. If it would be possible, I simply would have overridden the 
__str__ method of the original exception in the first place.

-- Chris





More information about the Python-list mailing list