Bez popisu
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.

exceptions.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #-*- coding: utf-8 -*-
  2. class LodelException(Exception):
  3. pass
  4. class LodelExceptions(LodelException):
  5. ##@brief Instanciate a new exceptions handling multiple exceptions
  6. # @param msg str : Exception message
  7. # @param exceptions dict : A list of data check Exception with concerned field (or stuff) as key
  8. def __init__(self, msg = "Unknow error", exceptions = None):
  9. self._msg = msg
  10. self._exceptions = dict() if exceptions is None else exceptions
  11. def __repr__(self):
  12. return self.__str__()
  13. def __str__(self):
  14. msg = self._msg
  15. for_iter = self._exceptions.items() if isinstance(self._exceptions, dict) else enumerate(self.__exceptions)
  16. for obj, expt in for_iter:
  17. msg += "\n\t{expt_obj} : ({expt_name}) {expt_msg}; ".format(
  18. expt_obj = obj,
  19. expt_name=expt.__class__.__name__,
  20. expt_msg=str(expt)
  21. )
  22. return msg
  23. ##@brief Designed to be a non catched exception.
  24. #
  25. #@note Designed to be raised in dramatic case
  26. class LodelFatalError(Exception):
  27. pass
  28. ##@brief Designed to be a catched exception.
  29. #
  30. #@note Designed to be raised in DataHandler
  31. class DataNoneValid(Exception):
  32. pass
  33. ##@brief Designed to be a catched exception.
  34. #
  35. #@note Designed to be raised in DataHandler
  36. class FieldValidationError(Exception):
  37. pass