When to use exceptions (was Re: reducing if statements...)
phr-n2001 at nightsong.com
Wed Aug 22 02:36:07 CEST 2001
> This always seemed pretty clumsy to me. I prefer to use exceptions:
> class done(Exception): pass
> for i in range(len(mylist)):
> for j in range(len(mylist[i])):
> if some_predicate(mylist[i][j]):
> raise done
> except done:
> print "didn't find anything interesting..."
> YMMV. Some people hate the construct. I think it's pretty Pythonic.
It's very normal do that in Lisp using catch/throw. Yet more evidence
that Python is just Lisp without parentheses :-)
More information about the Python-list