我经常发现自己想做这样的事情,我有一些东西包含在尝试中,除了这样
item= get_item()
try:
do_work(item)
except SomeError as err:
if err.code == 123:
do_something(item)
else:
# Actually I don't want to do something with this error code... I want to handle in 'except'
except:
put_back(item)
raise
有没有办法except
从其他地方提升到下面的街区?(acontinue
会很好)我最终做了类似下面的事情,但不是那么干净
item= get_item()
try:
try:
do_work(item)
except SomeError as err:
if err.code == 123:
do_something(item)
else:
raise
except:
put_back(item)
raise
有没有办法做到这一点?