title: Python 2.7: Save all exceptions into database (convert to unicode Problems)
body: <p>I am trying to save all exceptions thrown by a python service (running hidden on Windows 7/10) into a sqlite3 database file. In addition to other things(traceback, date, etc) I want to save the error message too. </p>
  
  <p>My Problem is that there are some error messages that I cannot convert to unicode (Especially some WindowsErrors and errors with a german 'Umlaut': ä, ö, ü). As I don't know every possible error in advance <strong>I want to have a function that can handle ALL errors and convert their message to unicode</strong>.</p>
  
  <p>Can someone tell me what the <strong>convertToUnicode</strong>-function has to look like?</p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  def someErrorneousFunction():
      raise RuntimeError('Not a unicode string. But with a german Umlaut: ä!')
  
  def saveExceptionToDBThatOnlyAcceptsUnicode(msg):
      """SQL INSERT SOME STUFF... + THE UNICODE ERROR MESSAGE!"""
      pass
  
  def convertToUnicode(e):
      """ What to do here ??? """
      pass
  
  try:
      someErrorneousFunction()
  except Exception as e:
      unicode_error_msg = convertToUnicode(e)
      saveExceptionToDBThatOnlyAcceptsUnicode(unicode_error_msg)
  </code></pre>
  
  <p><strong>Note:</strong> I found that some Exceptions have an attribute called <strong>.msg</strong> or <strong>.str</strong>, but not all of them!</p>
  
  <p>Does this method make sense at all? I know its bad practice to catch ALL exceptions with no distinction but as my software occasionally is in testmode somewhere else and I want to get the exception database per mail it seemed meaningful to me. Furthermore I distinguish the errors I know from those I don't know in advance.</p>
  
  <p>I would appreciate any advise!</p>
  
  <p>Thank you!</p>
  
  <p>Sebastian</p>