How can I specify this script to capture specifically the error 001566, instead of the current general execution error?

Error 001566:Failed to create raster dataset. The reason could be: The clip feature is outside the raster extent

    arcpy.Clip_management(lyr,rectangle='#',out_raster=out_feature, in_template_dataset = clip_feature, nodata_value="256", clipping_geometry="ClippingGeometry", maintain_clipping_extent="NO_MAINTAIN_EXTENT")
except arcpy.ExecutionError:

1 Answer 1


It's always going to raise an ExcecutionError, but one strategy could be to check the error string itself. For example:

except arcpy.ExecutionError as e:
    if 'Error 001566' not in str(e):
        raise  # re-raise the exception if it's not the error we're expecting
    # handle the error here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.