Coming from a C++ background where I learned to restrict the use of exceptions to exceptional circumstances, I was very surprised about Python's cheap exceptions. In fact, some language features like iteration seem to be build on exceptions being thrown. This makes sense when considering that the (python) interpreter has to guarantee its own integrity and thus does several checks anyway.
Does it make sense to expect cheap exceptions to be normal in interpreted languages?
Edit:
To make clear that this question doesn't address primarily performance, I should add that I try to expand my programming skills by learning new languages. I'd probably never use exceptions in non-exceptional circumstances in C++ or Pascal, but in python I obviously should (and this is maybe not the only language). And because it makes a structural difference for my code if I use or not use exceptions, a simple guideline/rule of thumb would help to get started in a new language..
See that in perspective:
In C++ all is cheap except exceptions;
In Python exceptions are about as time consuming as normal stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With