SetSeverityLevel

摘要

Used to control how geoprocessing tools throw exceptions.

讨论

If SetSeverityLevel is not used, the default behavior is equivalent to setting the severity_level to 2; that is, tools will only throw an exception when the tool has an error.

语法

SetSeverityLevel (severity_level)
参数说明数据类型
severity_level

The severity level

  • 0A tool will not throw an exception, even if the tool produces an error or warning.
  • 1If a tool produces a warning or an error, it will throw an exception.
  • 2If a tool produces an error, it will throw an exception. This is the default.
Integer

代码示例

SetSeverityLevel example

Use SetSeverityLevel to force tool to throw an exception when a tool warning is encountered.

import arcpy
from arcpy import env

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 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 
    #  through an exception.
    #
    arcpy.FeatureCompare_management(fc1, fc2, "OBJECTID")
except:
    print arcpy.GetMessages()

相关主题


7/10/2012