Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are "cheap exceptions" typical for interpreted languages?

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..

like image 290
Wolf Avatar asked Jun 04 '26 23:06

Wolf


1 Answers

See that in perspective:

In C++ all is cheap except exceptions;

In Python exceptions are about as time consuming as normal stuff.

like image 152
Klamer Schutte Avatar answered Jun 06 '26 14:06

Klamer Schutte