Newbie naive question ... int() throws ValueError

Devin Jeanpierre jeanpierreda at gmail.com
Sat May 12 00:11:18 EDT 2012


On Fri, May 11, 2012 at 11:21 PM, Chris Angelico <rosuav at gmail.com> wrote:
> There are times when you want to catch all exceptions, though.
> Top-level code will often want to replace exception tracebacks with
> error messages appropriate to some external caller, or possibly log
> the exception and return to some primary loop. Otherwise, though, most
> code will just let unexpected exceptions through.

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?

Apparently the answer is to read the documentation for ValueError.

It's a bit like putting the documentation on the return type for `map`
in the list documentation. Kinda hard to get there without already
knowing the answer.

-- Devin



More information about the Python-list mailing list