Try/except vs. if/else

Hung Jung Lu hungjunglu at
Sat Sep 27 10:25:10 CEST 2003

Tim Rowe <tim at> wrote in message news:<u941nvg94ae04ajndvbjs2hlqc9l5lemqh at>...
> On Tue, 23 Sep 2003 11:10:49 -0400, Shu-Hsien Sheu <sheu at>
> wrote:
> >In my understanding, using try/except rather than if/else is more 
> >pythonic. 
> Rule of thumb: when the block of code is still doing what it's
> supposed to do, use if/else. If it's failing to do what it's supposed
> to do, use try/except. "except" should be an /exception/!
> So try/except /only/ when something has gone wrong and you need to go
> into some sort of recovery or termination, /not/ for routine tests.

You have a valid point of view, which nonetheless is not shared by
everyone. This is a recurring subject in the newsgroup.

Python exceptions have been used for other purposes, as can be seen
from Python FAQ (e.g. "4.22 Why is there no goto?" in

The "for" loop in Python is also implemented internally with
exceptions. E.g.:,
where it mentioned:

"... In some other languages, 'non failure' mode exceptions may be
unusual, but it's the normal idiom in Python."


Hung Jung

More information about the Python-list mailing list