[Tutor] Class as Exception
Sean 'Shaleh' Perry
shalehperry@attbi.com
Sat Feb 8 20:13:40 2003
On Saturday 08 February 2003 14:30, Bob Gailer wrote:
> A couple of times I got the following to work. Now I just get an except=
ion.
>
> >>> class n(str):pass
> >>> raise n, 'tst'
>
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> TypeError: exceptions must be strings, classes, or instances, not type
>
> Why would the same code work, then fail?
>
1) when you want an exception, derive from Exception. class n(Exception)=
=2E
2) I believe you are suppose to raise an instance of the exception class,=
not=20
the class itself. "raise n(), 'tst'".