[Tutor] Exception attributes?
Alan Gauld
alan.gauld at blueyonder.co.uk
Sat Jul 10 20:47:39 CEST 2004
> I'm in the process of figuring out try: clauses and I've run into a
hitch.
>
> It seems that each exception has different attributes. How can I
discover
> what attributes are?
I assume you mean the different exception types? You can have
attributes
of exceptions too but I don't see those used all that often.
For the error type I use the >>> prompt and simply force an error then
see what kind of exception the error message gives.
eg:
>>> 7/0 -> ZeroDivisionError: integer division or modulo by zero
So I use
except ZeroDivisionError
>>> "fred" + 42 -> TypeError: cannot concatenate 'str' and 'int'
objects
So I use
except TypeError:
The >>> prompt is your friend.
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list