Chapter 11. Error Handling and Troubleshooting

In this chapter, we will cover the following recipes:

  • Exploring the default Python error message
  • Adding Python exception handling structures (try/except/else)
  • Retrieving tool messages with GetMessages()
  • Filtering tool messages by the level of severity
  • Testing for and responding to specific error messages

Introduction

Various messages are returned during the execution of ArcGIS geoprocessing tools and functions. These messages can be informational in nature or indicate warning or error conditions that can result in the tool not creating the expected output or result in outright failure of the tool to be executed. These messages do not appear as message boxes. Instead, you will need to retrieve them by using various ArcPy functions. Up to this point in the book, we have ignored the existence of these messages, warnings, and errors. This is mainly due to the fact that I wanted you to concentrate on learning some basic concepts, without adding the extra layer of code complexity that is necessary to create robust geoprocessing scripts that can handle error situations gracefully. This being said, it's now time that you learn how to create geoprocessing and Python exception handling structures that will enable you to create versatile geoprocessing scripts. These scripts can handle messages that indicate warnings, errors, and general information, which are generated while your script is running. These code details will help make your scripts more flexible and less error prone. You've already used the basic try and except blocks to perform some basic error handling. However, in this chapter, we'll go into more detail about why and how these structures are used.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset