Adding Python exception handling structures (try/except/finally)

Python has built-in exception handling structures that allow you to capture error messages that are generated. Using this error information, you can then display a more appropriate message to the end user and respond to the situation as needed.

Getting ready

Exceptions are unusual or error conditions that occur in your code. Exception statements in Python enable you to trap and handle errors in your code, allowing you to gracefully recover from error conditions. In addition to error handling, exceptions can be used for a variety of other things including event notification and special-case handling.

Python exceptions occur in two ways. Exceptions in Python can either be intercepted ...

Get Programming ArcGIS 10.1 with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.