我的一个脚本中出现特定错误:
ExecuteError: ERROR 000229: Cannot open F:\path\to\file.tif
我使用 try/except 块隔离了这些实例:
try:
#Do something
except:
#Do something in the event of failure
except
如何在语句中捕获上述特定的 ExecuteError ?
我的一个脚本中出现特定错误:
ExecuteError: ERROR 000229: Cannot open F:\path\to\file.tif
我使用 try/except 块隔离了这些实例:
try:
#Do something
except:
#Do something in the event of failure
except
如何在语句中捕获上述特定的 ExecuteError ?
你不能。但是您可以检查异常对象的各种属性以查看它是否是您关心的对象,否则重新引发异常。
try:
...
except ExecuteError as e:
if not can_handle(e):
raise
handle(e)
有点骇人听闻,但是如果您只想捕获 000229 ,则可以执行以下操作:
try:
# your code
except ExecuteError as err:
if str(err.message).startswith("ERROR 000229"):
# do something
else:
# do something else