捕获异常后返回'try'块 [英] Returning to 'try' block after catching an exception
问题描述
我不确定Python是否可以做到这一点,我无法在网上找到它。所以,
在这里:
试试:
some_function()
除了SomeException:
some_function2()
some_function3()
...
#somehow goto''try''再次阻止>
如果不清楚我的意思:执行some_function后()
异常SomeExcpetion会上升。然后,除了块我做了一些事情
修复导致异常的任何事情然后我想回去
尝试阻止,并再次执行some_function()。可行吗?
谢谢。
-
_______ Karlo Lozovina - Mosor
| | | ----- -----。 web: http://www.mosor.net || ICQ#:10667163
| || _ | _ | Parce mihi domine quia Dalmata sum。
| __ | _ | __ || _____ | _____ |
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?
Thanks.
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
推荐答案
5月21,8:13 pm,Karlo Lozovina< _karlo _ @ _ mosor.net_wrote:
On May 21, 8:13 pm, Karlo Lozovina <_karlo_@_mosor.net_wrote:
我不确定Python是否可以做到这一点,我可以''在网上找到它。那么,
就这样:
试试:
some_function()
除了SomeException之外的
:
some_function2()
some_function3()
...
#somehow goto''try''block再次
如果不清楚我的意思:执行some_function()之后
异常SomeExcpetion会升级。然后,除了块我做了一些事情
修复导致异常的任何事情然后我想回去
尝试阻止,并再次执行some_function()。那可行吗?
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?
如下所示(未经测试)
完成= False
而不是完成:
试试:
some_function()
done = True
除了:
some_function2()
some_function3()
$ b $bAndré
How about something like the following (untested)
done = False
while not done:
try:
some_function()
done = True
except:
some_function2()
some_function3()
André
> ;
谢谢。
-
_______ Karlo Lozovina - Mosor
| | | ----- -----。网址:http://www.mosor.net || ICQ#:10667163
| || _ | _ | Parce mihi domine quia Dalmata sum。
| __ | _ | __ || _____ | _____ |
>
Thanks.
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web:http://www.mosor.net|| ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
André< an *********** @ gmail.comwrote
新闻:a9 ********************************** @ s50g2000 hsb.googlegroups.com:
André <an***********@gmail.comwrote in
news:a9**********************************@s50g2000 hsb.googlegroups.com:
如下所示(未经测试)
完成= False
未完成时:
尝试:
some_function()
done = True
除了:
some_function2()
some_function3()
How about something like the following (untested)
done = False
while not done:
try:
some_function()
done = True
except:
some_function2()
some_function3()
当然,这很有效,但我的目标是更优雅和Pythonic
;)。
-
_______ Karlo Lozovina - Mosor
| | | ----- -----。 web: http://www.mosor.net || ICQ#:10667163
| || _ | _ | Parce mihi domine quia Dalmata sum。
| __ | _ | __ || _____ | _____ |
Sure, that works, but I was aiming for something more elegant and Pythonic
;).
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
Karlo Lozovina < _karlo _ @ _ mosor.net_wrote in message
news:Xn ********************* @ 161.53.160.65 ...
| André< an *********** @ gmail.com写在
|新闻:a9 ********************************** @ s50g2000 hsb.googlegroups.com:
|
|如下所示(未经测试)
| >
| done = False
|虽然没做完:
|试试:
| some_function()
| done = True
|除了:
| some_function2()
| some_function3()
|
|当然,这是有效的,但我的目标是更优雅的东西和
Pythonic
| ;)。
而真:
试试:
some_function()
break
除了例外:
补丁()
???
"Karlo Lozovina" <_karlo_@_mosor.net_wrote in message
news:Xn*********************@161.53.160.65...
| André <an***********@gmail.comwrote in
| news:a9**********************************@s50g2000 hsb.googlegroups.com:
|
| How about something like the following (untested)
| >
| done = False
| while not done:
| try:
| some_function()
| done = True
| except:
| some_function2()
| some_function3()
|
| Sure, that works, but I was aiming for something more elegant and
Pythonic
| ;).
while True:
try:
some_function()
break
except Exception:
patchup()
???
>
这篇关于捕获异常后返回'try'块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!