Synthèse
Controls how geoprocessing tools throw exceptions.
Discussion
If the SetSeverityLevel function is not used, the default behavior is equivalent to setting the severity_level argument to 2; that is, tools will only throw an exception when the tool has an error.
Syntaxe
SetSeverityLevel (severity_level)
Paramètre | Explication | Type de données |
severity_level | Specifies the severity level
| Integer |
Exemple de code
Use the SetSeverityLevel function to force tools to raise an exception when a tool warning is encountered.
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.management.FeatureCompare(fc1, fc2, "OBJECTID")
except arcpy.ExecuteWarning:
print(arcpy.GetMessages(1))
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?