[Python-Dev] Tidier Exceptions

Aahz aahz at pythoncraft.com
Mon May 16 15:58:17 CEST 2005


On Mon, May 16, 2005, Greg Ewing wrote:
> Aahz wrote:
>> On Fri, May 13, 2005, Greg Ewing wrote:
>>>
>>>Instead of an 'args' attribute, I'd suggest that the constructor take
>>>keyword arguments and store them in corresponding attributes.
>> 
>> Sounds reasonable, but it should be equally easy to handle::
>> 
>>     raise MyError, "message"
> 
> To be more explicit, the base exception class would
> look something like
> 
>    class Exception:
> 
>      def __init__(self, message = None, **kwds):
>        self.message = message
>        self.__dict__.update(kwds)
> 
>      def __str__(self):
>        if self.message is not None:
>          return self.message
>        else:
>          return self.__class__.__name__

That works.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"And if that makes me an elitist...I couldn't be happier."  --JMS


More information about the Python-Dev mailing list