Catching Python's OverflowError
after some dumb calculation, I checked the error's args
and saw it's a tuple containing an integer as its first coordinate. I assume this is some kind of error number (errno
). However, I could not find any documentation or reference for it.
Example:
try:
1e4**100
except OverflowError as ofe:
print ofe.args
## prints '(34, 'Numerical result out of range')'
Do you know what 34
means in this context? Do you know other possible error numbers for this exception?
There is a module in the standard library called
errno
:/usr/include/linux/errno.h
includes/usr/include/asm/errno.h
that includes/usr/include/asm-generic/errno-base.h
.Now we know that the 34 error code stands for ERANGE.
1e4**100
is processed withfloat_pow
function from Object/floatobject.c. Partial source code of that function:So,
1e4**100
causes ERANGE error (resulting inPyExc_OverflowError
) and then the higher levelOverflowError
exception raises.