How to name Exceptions that aren't Errors
Steve Holden
steve at holdenweb.com
Fri Apr 8 12:23:59 EDT 2005
Leif K-Brooks wrote:
> Steve Holden wrote:
>
>> I've even used an exception called Continue to overcome an irksome
>> restriction in the language (you used not to be able to continue a
>> loop from an except clause).
>
>
> Out of curiosity, how could you use an exception to do that? I would
> think you would need to catch it and then use "continue", which wouldn't
> be possible because of the restriction you were trying to work around in
> the first place.
As long as the exception-handling code doesn't break then the loop
automatically continues, so the trick was (IIRC) to have a loop body
that essentially looked like this:
for item in somelist:
try:
{loop body}
except Continue:
pass
Then exceptions caught inside the loop body (which obviously had nested
try: clauses) could raise Continue inside their except: clause to
restart the loop at the next iteration.
regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
More information about the Python-list
mailing list