Newbie naive question ... int() throws ValueError

Chris Angelico rosuav at gmail.com
Sat May 12 01:50:56 EDT 2012


On Sat, May 12, 2012 at 2:11 PM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
> I'm not talking about unexpected exceptions. I'm saying, if I expect
> invalid input for int, where should I go to find out how to deal with
> said invalid input properly? How do I know that int raises ValueError
> on failure, and not, for example, something like ArgumentError
> (something that Python doesn't have) or (like chr) TypeError?

Ah, I see what you mean.

The easiest way to find out what exception gets thrown is to try it.
For obvious things like int("foo") you can simply test it in the
interactive interpreter; unusual cases you'll discover as you run your
script.

ChrisA



More information about the Python-list mailing list