title: Best Practices for Python Exceptions?
body: <p>What are the best practices for creating exceptions? I just saw this, and I don't know if I should be horrified, or like it. I read several times in books that exceptions should never ever hold a string, because strings themselves can throw exceptions. Any real truth to this?</p>
  
  <p>Basically from my understanding from the scripts is that this was done so all the inhouse Python libraries will have a common error message format (something that is desperately needed) so I can understand why putting the error message string is a good idea. (Almost every method throws exceptions due to the utter need for nothing invalid getting through).</p>
  
  <p>The code in question is the following:</p>
  
  <pre><code>"""
  Base Exception, Error
  """
  class Error(Exception):
      def __init__(self, message):
          self.message = message
  
      def __str__(self):
          return "[ERROR] %s\n" % str(self.message)
  
      def log(self):
          ret = "%s" % str(self.message)
          if(hasattr(self, "reason")):
              return "".join([ret, "\n==&gt; %s" % str(self.reason)])
          return ret
  
  class PCSException(Error):
      def __init__(self, message, reason = None):
          self.message = message
          self.reason = reason
      def __str__(self):
          ret = "[PCS_ERROR] %s\n" % str(self.message)
          if(self.reason != None):
              ret += "[REASON] %s\n" % str(self.reason)
          return ret
  </code></pre>
  
  <p>This is just the tip of the iceberg, but can someone give me some insight in what makes this a terrible idea? Or if there is a much better exception coding process/style.</p>