Extending Python: exception handling
Skip Montanaro
skip at mojam.com
Sat Aug 21 20:50:51 EDT 1999
John> I would like to know how YOU are using exception handling OTHER
John> than for error management.
It makes a reasonable substitute for the lack of labelled break statements
on certain occasions.
class BreakLabel: pass
try:
for i in ...:
for j in ...:
exit_cond = do_some_work()
if exit_cond: raise BreakLabel
except BreakLabel:
pass
instead of
for i in ...:
exit_cond2 = 0
for j in ...:
exit_cond = do_some_work()
if exit_cond:
exit_cond2 = 1
break
if exit_cond2: break
Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/~skip/
847-971-7098 | Python: Programming the way Guido indented...
More information about the Python-list
mailing list