Package Gnumed :: Package pycommon :: Module gmExceptions |
[frames] | no frames]

# Source Code for Module Gnumed.pycommon.gmExceptions

     1  ############################################################################
     2  # gmExceptions - classes for exceptions GNUmed modules may throw
     3  # --------------------------------------------------------------------------
     4  #
     5  # @author: Dr. Horst Herb
     6  # @copyright: author
     7  # @license: GPL v2 or later (details at http://www.gnu.org)
     8  # @dependencies: nil
     9  # @change log:
    10  #       07.02.2002 hherb first draft, untested
    11  ############################################################################
    12
    13 -class AccessDenied(Exception):
    14 -        def __init__(self, msg, source=None, code=None, details=None):
    15                  self.errmsg = msg
    16                  self.source = source
    17                  self.code = code
    18                  self.details = details
    19          #----------------------------------
    20 -        def __str__(self):
    21                  txt = self.errmsg
    22                  if self.source is not None:
    23                          txt += '\nSource: %s' % self.source
    24                  if self.code is not None:
    25                          txt += '\nCode: %s' % self.code
    26                  if self.details is not None:
    27                          txt += '\n%s' % self.details
    28                  return txt
    29          #----------------------------------
    30 -        def __repr__(self):
    31                  txt = self.errmsg
    32                  if self.source is not None:
    33                          txt += '\nSource: %s' % source
    34                  if self.code is not None:
    35                          txt += '\nCode: %s' % self.code
    36                  if self.details is not None:
    37                          txt += '\n%s' % self.details
    38                  return txt
    39
    40  #------------------------------------------------------------
    41 -class ConnectionError(Exception):
    42          #raised whenever the database backend connection fails
    43 -        def __init__(self, errmsg):
    44                  self.errmsg=errmsg
    45
    46 -        def __str__(self):
    47                  return self.errmsg
    48
    49  #------------------------------------------------------------
    50  # constructor errors
    51 -class ConstructorError(Exception):
    52          """Raised when a constructor fails."""
    53 -        def __init__(self, errmsg = None):
    54                  if errmsg is None:
    55                          self.errmsg = "%s.__init__() failed" % self.__class__.__name__
    56                  else:
    57                          self.errmsg = errmsg
    58 -        def __str__(self):
    59                  return self.errmsg
    60
    61  # business DB-object exceptions
    62 -class NoSuchBusinessObjectError(ConstructorError):
    63          """Raised when a business db-object can not be found."""
    64 -        def __init__(self, errmsg = None):
    65                  if errmsg is None:
    66                          self.errmsg = "no such business DB-object found"
    67                  else:
    68                          self.errmsg = errmsg
    69 -        def __str__(self):
    70                  return self.errmsg
    71
    72  #=====================================================================
    73