Returning to 'try' block after catching an exception

André andre.roberge at gmail.com
Wed May 21 19:20:33 EDT 2008


On May 21, 8:13 pm, Karlo Lozovina <_karlo_ at _mosor.net_> wrote:
> I'm not sure if Python can do this, and I can't find it on the web. So,
> here it goes:
>
> try:
>     some_function()
> except SomeException:
>     some_function2()
>     some_function3()
>     ...
>     # somehow goto 'try' block again
>
> In case it's not clear what I meant: after executing some_function()
> exception SomeExcpetion gets risen. Then, in except block I do something
> to fix whatever is causing the exception and then I would like to go back
> to try block, and execute some_function() again. Is that doable?

How about something like the following (untested)

done = False
while not done:
  try:
     some_function()
     done = True
  except:
     some_function2()
     some_function3()

André


>
> Thanks.
>
> --
>  _______                                        Karlo Lozovina - Mosor
> |   |   |.-----.-----.     web:http://www.mosor.net|| ICQ#: 10667163
> |       ||  _  |  _  |             Parce mihi domine quia Dalmata sum.
> |__|_|__||_____|_____|




More information about the Python-list mailing list