我必须处理大量的尝试/除外。我怀疑这样做的正确方法。
选项1:
inst = Some(param1, param2)
try:
is_valid = retry_func(partial(inst.some_other), max_retry=1)
except RetryException, e:
SendMail.is_valid_problem(e)
if is_valid:
print "continue to write your code"
...
*** more code with try/except ***
...
选项 2:
inst = Some(param1, param2)
try:
is_valid = retry_func(partial(inst.some_other), max_retry=1)
if is_valid:
print "continue to write your code"
...
*** more code with try/except ***
...
except RetryException, e:
SendMail.is_valid_problem(e)
在选项 1 中,即使引发异常,也会测试“is_valid”,我不需要它。
在选项 2 中,我认为是正确的,但代码看起来像“回调地狱”。
我应该选择哪个选项或哪个选项是正确的?