exceptions == errors?

Jim Meyer jmeyer at pdi.com
Tue Apr 8 11:54:00 EDT 2003


Hello!

On Mon, 2003-04-07 at 17:20, Skip Montanaro wrote:
>     Mark> Are exceptions always considered errors, or there the same feeling
>     Mark> as in C++ that exceptions can be used for non-error situations?
> 
> Exceptions are frequently used to signal non-error conditions.  For example,
> they can be used to break out of nested loops:

It's always been my impression that exceptions impose considerable
performance overhead and therefore should be used to handle only the
truly exceptional cases; for any predictable case, one should perform
validation and/or error-handling outside the exception mechanism. 

[BTW, I picked up this habit after reading "Effective C++" by Scott
Meyers, a book I cannot recommend highly enough. =]

Some meager benchmarking of Python's performance when handling
exceptions back around v1.6 seemed to indicate that there was a
performance hit. I just went digging for the data from those runs and
can't find it, so I'll be very vague and say that what I saw didn't
dissuade me from using them but persuaded me to use them judiciously.

The counter argument can be found in the archives of this list about a
year ago, which thread starts at http://tinyurl.com/92lv and ends with a
pointer to http://tinyurl.com/92m1 . The thread could be summarized by
saying that you should always implement, profile, and optimize the slow
bits (very true =); and that the performance penalty for exceptions is
distributed over the whole of Python, whether or not you use them.

I wonder if anyone has done recent benchmarking and can offer results
that indicate one direction or another? If not, I'll probably get around
to it in the next six months or so. ;p

Cheers!

--j
-- 
Jim Meyer, Geek at Large                                  jmeyer at pdi.com






More information about the Python-list mailing list