Newbie naive question ... int() throws ValueError

Chris Angelico rosuav at gmail.com
Fri May 11 12:23:04 EDT 2012


On Sat, May 12, 2012 at 2:15 AM, Christian Heimes <lists at cheimes.de> wrote:
> Am 11.05.2012 17:51, schrieb Terry Reedy:
>> If the domain of a function is truly all Python objects, it cannot raise
>> an error. I believe id(x) is such an example.
>
> Even id() can raise an exception, for example MemoryError when you are
> running out of memory.

KeyboardInterrupt can also be raised at (effectively) any time, but
I'm not sure that that really counts as id() raising the exception. If
I understand it correctly, MemoryError would be because the
interpreter can't allocate an int object for id's return value.

But these are definitely part of why you don't just catch all exceptions.

Hmm. What happens if the interpreter can't construct a MemoryError exception?

ChrisA



More information about the Python-list mailing list