Re: Fwd: Should I use "if" or "try" (as a matter of speed)?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Fwd: Should I use "if" or "try" (as a matter of speed)?

From: Roy Smith <roy@panix.com>
Date: Tue Jul 12 2005 - 22:53:49 CEST

Christopher Subich <spam.csubich+block@block.subich.spam.com> wrote:
>try:
> f = file('file_here')
> do_setup_code
> do_stuff_with(f)
>except IOError: # File doesn't exist
> error_handle

It's also a good idea to keep try blocks as small as possible, so you
know exactly where the error happened. Imagine if do_setup_code or
do_stuff_with(f) unexpectedly threw an IOError for some reason totally
unrelated to the file not existing.
Received on Thu Sep 29 16:54:54 2005