描述
用于控制地理处理工具如何抛出异常。
说明
如果未使用 SetSeverityLevel,默认行为等效于将 severity_level 设置为 2;即,仅当工具出错时,才会抛出异常。
语法
SetSeverityLevel (severity_level)
参数 | 说明 | 数据类型 |
severity_level | The severity level
| Integer |
代码示例
SetSeverityLevel 示例
使用 SetSeverityLevel 可强制工具在遇到工具警告时抛出异常。
import arcpy
fc1 = 'c:/resources/resources.gdb/boundary'
fc2 = 'c:/resources/resources.gdb/boundary2'
# Set the severity level to 1 (tool warnings will throw an exception)
arcpy.SetSeverityLevel(1)
print("Severity is set to : {0}".format(arcpy.GetSeverityLevel()))
try:
# FeatureCompare returns warning messages when a miscompare is
# found. This normally would not cause an exception, however, by
# setting the severity level to 1, all tool warnings will also
# return an exception.
arcpy.FeatureCompare_management(fc1, fc2, "OBJECTID")
except arcpy.ExecuteWarning:
print(arcpy.GetMessages(1))
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))