Stephen R Laniel wrote:

> End goal being that string exceptions would cause
> compilation to fail. A few times now, I've found myself
> doing
> 
> class SomeClass:
>     """docstring"""
>     pass
> 
> raise SomeClass, "Some description"
> 
> and I've gotten a weird compiler error about the constructor
> for SomeClass.

weird as in

    TypeError: this constructor takes no arguments

?

this has nothing to do with string exceptions (using string objects as 
exception objects), and all to do with the fact that

     raise SomeClass, "Some description"

is equivalent to

     raise SomeClass("Some description")

which of course doesn't work if your class constructor isn't accepting 
any arguments.  this is no different from doing:

     class SomeClass:
         pass

     obj = SomeClass("an argument") # fails with a TypeError

(note that it's the runtime that's complaining, not the compiler)

to fix this, just make sure that your exception class takes an argument 
(the exception value), either by adding an __init__ method, or by 
inheriting from a suitable built-in exception class.

</F>

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to