ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

AddError

  • Summary
  • Syntax
  • Code sample

Summary

Adds an error message (severity of 2) to the messages of a script tool or Python toolbox tool.

When a tool is run, arcpy is fully aware of the application from which it is called. One major effect of this is that you can write messages in Python and your messages automatically appear on the tool dialog box, in the history, and in the Python window.

Syntax

AddError (message)
ParameterExplanationData Type
message

The error message to add.

String

Code sample

AddError example

Add a custom geoprocessing error message.

import arcpy

fc = arcpy.GetParameterAsText(0)

# Get the count from the GetCount tool's Result object
feature_count = int(arcpy.GetCount_management(fc)[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

  • AddIDMessage
  • AddMessage
  • AddReturnMessage
  • AddWarning
  • GetMessage
  • GetMessageCount
  • GetMessages
  • GetReturnCode
  • Writing messages in script tools
  • Understanding message types and severity
  • Understanding messages in script tools

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal