error.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. This module houses the OGR & SRS Exception objects, and the
  3. check_err() routine which checks the status code returned by
  4. OGR methods.
  5. """
  6. #### OGR & SRS Exceptions ####
  7. class GDALException(Exception):
  8. pass
  9. class OGRException(Exception):
  10. pass
  11. class SRSException(Exception):
  12. pass
  13. class OGRIndexError(OGRException, KeyError):
  14. """
  15. This exception is raised when an invalid index is encountered, and has
  16. the 'silent_variable_feature' attribute set to true. This ensures that
  17. django's templates proceed to use the next lookup type gracefully when
  18. an Exception is raised. Fixes ticket #4740.
  19. """
  20. silent_variable_failure = True
  21. #### OGR error checking codes and routine ####
  22. # OGR Error Codes
  23. OGRERR_DICT = {
  24. 1: (OGRException, 'Not enough data.'),
  25. 2: (OGRException, 'Not enough memory.'),
  26. 3: (OGRException, 'Unsupported geometry type.'),
  27. 4: (OGRException, 'Unsupported operation.'),
  28. 5: (OGRException, 'Corrupt data.'),
  29. 6: (OGRException, 'OGR failure.'),
  30. 7: (SRSException, 'Unsupported SRS.'),
  31. 8: (OGRException, 'Invalid handle.'),
  32. }
  33. OGRERR_NONE = 0
  34. def check_err(code):
  35. "Checks the given OGRERR, and raises an exception where appropriate."
  36. if code == OGRERR_NONE:
  37. return
  38. elif code in OGRERR_DICT:
  39. e, msg = OGRERR_DICT[code]
  40. raise e(msg)
  41. else:
  42. raise OGRException('Unknown error code: "%s"' % code)