Wednesday 17 March 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.

Are there any resources that explain how the Python exception handling was implemented internally and if special optimizations were made because of the EAFP principle?



from How is exception handling implemented in Python?

No comments:

Post a Comment