Returning to 'try' block after catching an exception
Karlo Lozovina
_karlo_ at _mosor.net_
Thu May 22 04:19:40 EDT 2008
Duncan Booth <duncan.booth at invalid.invalid> wrote in
news:Xns9AA6596091F47duncanbooth at 127.0.0.1:
> Catching only the specific exceptions you think you can handle would
> be more Pythonic: that way things like sys.exit() will still work
> inside some_function.
I know, this was just a somewhat poorly example ;).
> I prefer a 'for' loop rather than 'while' so I can limit the number of
> retries.
>
> The following may or may not be 'more pythonic', but is something I've
> used. It's a factory to generate decorators which will retry the
> decorated function. You have to specify the maximum number of retries,
> the exceptions which indicate that it is retryable, and an optional
> filter function which can try to do fixups or just specify some
> additional conditions to be tested.
Interesting approach, I think I'll use something like that for avoding
infinite loops. Thanks a lot...
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
More information about the Python-list
mailing list