Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

except for exit code 9 ?

+4 votes
asked Feb 18, 2025 by jfmaheux (210 points)
is there a way to handle exit code 9?

something like this does not work....

try:
    print(2**4700063479)
except:
    print("That's too much now")

1 Answer

0 votes
answered Feb 19, 2025 by Peter Minarik (101,420 points)

I do not know Python very well. I do not understand how it works under the hood.

If you entered a smaller exponent, your code works. E.g.

If you'd written

print(2**100000)

then the except block would have executed.

Again, I do not understand how Python works under the hood. I suspected the exponent is maybe limited to (uint32_max) 232-1 or (int32_max) 231-1. But that's not the case.

In my experimentation, the last exponent where a Value Error was thrown (and could be caught) was 2595262094 and at the next value, 2595262095, error code 9 was the result.

I suspect what happens is that the server running the code runs out of memory during the calculation sooner than it would realize that there will be a Value Error so the program crashes.

But this is just a hunch.

Also, the limit where this crash (Error Code 9) happens varies every time, as the server's resources change all the time (depending on how many users are using it, what's running on the machine, etc).

commented Feb 19, 2025 by jfmaheux (210 points)
Thanks for this.
It is not a python error (we are just using integer here). These are all related to the server limit.
The error we get with n= 100000 is a different kind: valueError for writing the result, too many digits.
Code 9 is related to the memory allocated by onlinegdb to run a process, even before getting at the point where it would have to print the result, yes. Probably related to the whole request so I suppose even catching it would not help since the program would not be able to continue (because the allocated memory is used up).
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...