Ingen beskrivning
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 972B

123456789101112131415161718192021222324252627
  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