ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: slow try statements in python?
by Greg Ewing (using news.cis.dfn.de) other posts by this author
Feb 17 2003 10:57PM messages near this date
slow try statements in python? | Re: slow try statements in python?
Mark Higgins wrote:

>  I've seen quite a few examples of python code where try statements are 
>  used to control the flow of a program... seems reasonable, but with my 
>  background in C++ I'm always concerned that try statements are slow.
>  
>  Is this a concern in python?
>  

Not really. Raising and catching an exception is no more
expensive than many other things that Python programs do
a lot of, e.g. calling methods.

C++ implementations tend to be heavily optimised towards
the case where no exceptions are raised, on the assumption
that exceptions truly are "exceptional". But there is no
such bias in Python -- you're meant to be able to use
exceptions freely.

In fact, exceptions are used heavily under the covers
in places where you might not expect them. Every for-loop,
for example, is terminated by an exception. So if you're
afraid of exceptions, you'd better be afraid of using
for-loops, too!-)

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Mark Higgins
Greg Ewing (using news.cis.dfn.de)
Andrew MacIntyre
Erik Max Francis

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved