You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """
  2. This module houses the GDAL & SRS Exception objects, and the
  3. check_err() routine which checks the status code returned by
  4. GDAL/OGR methods.
  5. """
  6. # #### GDAL & SRS Exceptions ####
  7. class GDALException(Exception):
  8. pass
  9. class SRSException(Exception):
  10. pass
  11. # #### GDAL/OGR error checking codes and routine ####
  12. # OGR Error Codes
  13. OGRERR_DICT = {
  14. 1: (GDALException, 'Not enough data.'),
  15. 2: (GDALException, 'Not enough memory.'),
  16. 3: (GDALException, 'Unsupported geometry type.'),
  17. 4: (GDALException, 'Unsupported operation.'),
  18. 5: (GDALException, 'Corrupt data.'),
  19. 6: (GDALException, 'OGR failure.'),
  20. 7: (SRSException, 'Unsupported SRS.'),
  21. 8: (GDALException, 'Invalid handle.'),
  22. }
  23. # CPL Error Codes
  24. # https://www.gdal.org/cpl__error_8h.html
  25. CPLERR_DICT = {
  26. 1: (GDALException, 'AppDefined'),
  27. 2: (GDALException, 'OutOfMemory'),
  28. 3: (GDALException, 'FileIO'),
  29. 4: (GDALException, 'OpenFailed'),
  30. 5: (GDALException, 'IllegalArg'),
  31. 6: (GDALException, 'NotSupported'),
  32. 7: (GDALException, 'AssertionFailed'),
  33. 8: (GDALException, 'NoWriteAccess'),
  34. 9: (GDALException, 'UserInterrupt'),
  35. 10: (GDALException, 'ObjectNull'),
  36. }
  37. ERR_NONE = 0
  38. def check_err(code, cpl=False):
  39. """
  40. Check the given CPL/OGRERR and raise an exception where appropriate.
  41. """
  42. err_dict = CPLERR_DICT if cpl else OGRERR_DICT
  43. if code == ERR_NONE:
  44. return
  45. elif code in err_dict:
  46. e, msg = err_dict[code]
  47. raise e(msg)
  48. else:
  49. raise GDALException('Unknown error code: "%s"' % code)