I recently asked a question on SO where I was trying to understand how to catch an exception in a piece of code which runs indefinitely. I was initially expecting that
try:
the_code_which_runs_indefinitely_and_which_raises_an_exception()
except:
print('the exception in the code which runs indefinitely was caught')
would work (the actual Python code is in the linked question - I am asking on SE because I want to understand the reason of the choice in the implementation rather than a solution (though if there would be one for my specific problem it would be great as well)).
It does not. As mentioned in the question, my wild guess is that the try
/except
construction is not in place yet (and will never be) while the_code_which_runs_indefinitely_and_which_raises_an_exception()
runs.
What are the design reasons behind the decision to have exceptions which cannot be intercepted (when the catching mechanism is well in place, and in the case of Python even encouraged)?