Cost of raising exceptions.

Aahz Maruch aahz at panix.com
Wed May 30 19:33:57 EDT 2001


In article <mailman.991144423.30414.python-list at python.org>,
Allan Crooks  <amc1 at dcs.qmw.ac.uk> wrote:
>
>I'm fairly new to Python (I fear that's always a bad way to start a
>sentence), but rather curious at the same time. Which leads me to this
>question:
>
> Are raising exceptions a costly operation?

Raising an exception is costly; executing a try block *without* an
exception is cheap.  Overall, if using an exception feels natural, go
ahead and use it.  Do the profiling *after* you've written your program
in a natural and readable style.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het Pythonista   http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Characters exist to suffer, you know.  An author needs a little sadism
in her makeup."  --Brenda Clough



More information about the Python-list mailing list