Re-raising exceptions with modified message

Christoph Zwerschke cito at online.de
Thu Jul 5 17:56:15 EDT 2007


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, PoliteException):
             return str(self._e)
         else:
             return '\n%s: %s, I am sorry!' % (
                 self._e.__class__.__name__, str(self._e))

try:
     unicode('\xe4')
except Exception, e:
     raise PoliteException(e)



More information about the Python-list mailing list