What does ArcPy do when a tool is run?

What does ArcPy do when a tool is run?

When a tool is run, ArcPy identifies the application it is called from. This allows you to write messages in Python. Those messages automatically appear on the tool dialog box, in Geoprocessing history, and in the Python window. It also means that any model or script tool that calls your tool has access to the messages you write.

What happens when you call a script in ArcGIS Pro?

Upon return from your script, the calling script or model receives a system error and execution stops. In the example below, the input is evaluated, and if it contains no input features, an error message is added to the tool and an arcpy.ExecuteError exception is raised to end the tool.

Where do I Find my Messages in Python?

This allows you to write messages in Python. Those messages automatically appear on the tool dialog box, in Geoprocessing history, and in the Python window. It also means that any model or script tool that calls your tool has access to the messages you write.

How to handle geoprocessing errors in ArcPy pro?

When a geoprocessing tool fails, it throws an arcpy.ExecuteError exception class, which means that you can divide errors into different groups, geoprocessing errors (those that throw the arcpy.ExecuteError exception) and other exception types. You can then handle the errors differently, as demonstrated in the code below:

How to handle an error message in Python?

The following sections offer a few techniques that introduce the basics of Python exception handling. When a tool writes an error message, ArcPy generates an arcpy.ExecuteError exception. Python allows you to write a routine that automatically runs when a system error is generated.

What does the try statement in ArcPy do?

If not, AddError will have no effect. arcpy.AddError (e.args [ 0 ]) The try statement has an optional finally clause that can be used for tasks that should always be executed, whether an exception occurs or not.

How are messages written in a geoprocessing tool?

During execution of a tool, messages are written that can be retrieved with geoprocessing functions. The four ArcPy functions for writing messages are as follows: An informative message is added to the tool’s messages. A warning message is added to the tool’s messages.

How do you add message to script tool?

A warning message is added to the tool’s messages. An error message is added to the tool’s messages. A message of any type is added using geoprocessing message codes. A call to AddIDMessage displays a short message and the message ID, which is a link to an explanation about the cause of and solutions to the problem.