[Tutor] a question about exceptions

Karl Pflästerer sigurd at 12move.de
Mon Mar 22 10:54:40 EST 2004


On 22 Mar 2004, Tony  Cappellini <- tony at tcapp.com wrote:

> I've found this code on the net- I think it was from the Python Cookbook.

>          try:
>             Celsius=float(string.atoi(CTemp))
>          except string.atoi_error:
>             print repr(CTemp), "not a numeric value"
>          else:

This code is very outdated.  Today with a recent python noone would
write it like that.


> I understand what's happening-in general. What I don't understand is
> the exception type
> string.atoi_error.

This is from the string module.  If you import it you will see that
error.  But `atoi' should no longer be used; `int' is better.

[...]
> So where is this type of exception defined and documented ? What other
> kinds of exception types like this exist ?

It's defined and documented in the string module.

> This type of exception handling opens up a whole lot of possibilities,
> if I could only find out where to get documentation.

Perhaps you should read about how to subclass your own exceptions from
existing exception classes (in the Python tutorial).  Also read perhaps
about `raise'.


   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list