Package grizzled :: Module exception
[hide private]
[frames] | no frames]

Source Code for Module grizzled.exception

 1  # $Id: 2f91144fd898abfc5994a3a7de580cde341c5c07 $ 
 2   
 3  """ 
 4  Provides some base exception classes. 
 5  """ 
 6   
 7  __docformat__ = "restructuredtext en" 
 8   
 9  # --------------------------------------------------------------------------- 
10  # Exports 
11  # --------------------------------------------------------------------------- 
12   
13  __all__ = ['ExceptionWithMessage'] 
14 15 # --------------------------------------------------------------------------- 16 # Classes 17 # --------------------------------------------------------------------------- 18 19 -class ExceptionWithMessage(Exception):
20 """ 21 Useful base class for exceptions that have a single exception message 22 argument. Among other things, this method provides a reasonable default 23 ``__str__()`` method. 24 25 Usage: 26 27 .. python:: 28 29 from grizzled.exception import ExceptionWithMessage 30 31 class MyException(ExceptionWithMessage): 32 def __init__(self, msg): 33 ExceptionWithMessage.__init__(self, msg) 34 """
35 - def __init__(self, errorMessage):
36 """ 37 Create a new exception. 38 39 @type errorMessage: string 40 @param errorMessage: the error message 41 """ 42 self.__message = errorMessage
43 44 @property
45 - def message(self):
46 """ 47 The message stored with this object. 48 """ 49 return self.__message
50
51 - def __str__(self):
52 return '%s: %s' % (self.__class__.__name__, self.__message)
53