[Tutor] a question about exceptions

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Mon Mar 22 11:13:14 EST 2004


hi Tony,

I don't know if you know this, but in the C programming language there is
an atoi() function that converts an array to int.  During runtime you will
get an error if what is passed is not an array or, in the case of an
array of chars, if not every char is a digit.  I don't know enough of
Python to say anymore than what I have learned in my community college C
class.

I hope this helps you.

On Mon, 22 Mar 2004, Tony  Cappellini wrote:

>
>
> Recently,
>
> 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:
>
>
> I understand what's happening-in general. What I don't understand is the
> exception type
> string.atoi_error.
>
> Where is this type of exception defined ? I couldn't find anything on
> exceptions other than the built-in exception classes, in the Python docs,
> and the books I have on Python.
>
> So where is this type of exception defined and documented ? What other
> kinds of exception types like this exist ?
>
> This type of exception handling opens up a whole lot of possibilities, if I
> could only find out where to get documentation.
>
> thanks
>
> Tony




More information about the Tutor mailing list