AddError (arcpy)

Summary

Creates a geoprocessing tool error message (Severity=2) that can be accessed by any of the GetMessages functions.

Syntax

AddError (message)
ParameterExplanationData Type
message

The message to add.

String

Code Sample

AddError example

Add custom geoprocessing error message.

import arcpy

fc = arcpy.GetParameterAsText(0)

# Get the count from GetCount's Result object
feature_count = int(arcpy.GetCount_management(fc).getOutput(0))

if feature_count == 0:
    arcpy.AddError("{0} has no features.".format(fc))
else:
    arcpy.AddMessage("{0} has {1} features.".format(fc, feature_count))

Related Topics

6/21/2013