Thursday, 14 October 2021

How is exception handling implemented in Python?

This question asked for explanations of how exception handling is implemented under the hood in various languages but it did not receive any responses for Python.

I'm especially interested in Python because Python somehow "encourages" exception throwing and catching via the EAFP principle.

I've learned from other SO answers that a try/catch block is cheaper than an if/else statement if the exception is expected to be raised rarely, and that it's the call depth that's important because filling the stacktrace is expensive. This is probably principally true for all programming languages.

What's special about python though is the high priority of the EAFP principle. How are python exceptions therefore implemented internally in the reference implementation (CPython)?



from How is exception handling implemented in Python?

No comments:

Post a Comment