【发布时间】:2014-04-22 07:13:14
【问题描述】:
我有多个函数可能会返回None:
do_something()、do_something2()、do_something3()等
为了克服无类型错误,我必须从代码的另一部分硬编码try-except:
try:
x = do_other_things(do_something())
except someError: # because of None Type return
x = None
try:
y = do_other_things(do_something2())
except someError: # because of None Type return
y = None
有什么方法可以将相同的try-except 应用于不同的代码行/不同的函数调用?
【问题讨论】:
标签: python error-handling try-catch except hardcode