描述
地理处理工具遇到警告时,将触发 ExecuteWarning 异常类,并且 SetSeverityLevel 函数将严重性级别更新为 1。将严重性级别设置为 1 后,将在遇到警告时指示 arcpy 抛出 ExecuteWarning 异常。
代码示例
ExecuteWarning 异常示例
在下面的代码中,ExecuteWarning 类专门用于处理任何由 DeleteFeatures 导致的地理处理工具错误。
import arcpy
try:
# If a tool produces a warning, it will throw an exception
arcpy.SetSeverityLevel(1)
# Note: DeleteFeatures on a feature class will always return a warning
arcpy.DeleteFeatures_management("c:/base/transport.gdb/roads")
except arcpy.ExecuteWarning:
print(arcpy.GetMessages())