title: Customizing exceptions in python? writing logs in custom exception class?
body: <p>I am customizing exceptions in my python code. I have inherited exception class in to other and now defining some custom errors as classes derived from my custom exception class like this:</p>
  
  <pre><code>class DataCollectorError(Exception): pass
  class ParamNullError(DataCollectorError) : pass
  class ParamInvalidTypeError(DataCollectorError) : pass
  </code></pre>
  
  <p>I am raising these exceptions in my python function like:</p>
  
  <pre><code>def READ_METER_DATA (regIndex, numRegisters, slaveUnit):
      try:
          if not regIndex:
              raise ParamNullError, "register index is null"
  
          if not numRegisters:
              raise ParamNullError, "number of registers should not be null"
  
          if not slaveUnit:
              raise ParamNullError, "Meter Id should not be null"
  </code></pre>
  
  <p>and logging error like :</p>
  
  <pre><code>except DataCollectorError as d:
      lgr.error('DataCollector Error(READ_METER_DATA): '+d.args[0])
      print 'DataCollector Error:(READ_METER_DATA)', d.args[0]
  except:
      lgr.error('Unexpected Error: ', sys.exc_info())
      print 'Unexpected Error: ', sys.exc_info()
      pass
  </code></pre>
  
  <p>but this defeats purpose of unit testing script as it doesn't whether exception raised bcz it is being catched by my catch block before my unit test script knows it. so i wanted to log these errors in base class itself - </p>
  
  <pre><code>Class ParamNullError(DataCollectorError):
      &lt;----here-----------&gt;
      pass 
  </code></pre>
  
  <p>can anybody tell me how to fetch that string passed while raising exception?</p>