title: Determine Error/Exception Type Python
body: <p>I am using the win32Com module to write data to an excel sheet on a Windows 7 machine with Python 3.5. While it is running I get thrown an error. I tried making a "try/except" block but the error type I attempted is apparently not an actual error type. Here is my code : </p>
  
  <pre><code>import win32com.client as win32
  import sqlite3
  
  def writeWords(storage):
  excel = win32.gencache.EnsureDispatch('Excel.Application')
  excel.Visible = True
  wb = excel.Workbooks.Add()
  ws = wb.Worksheets('Sheet1')
  i = 0 
  storLen = len(storage)
  while i &lt; storLen:
      varX = storage[i]
      lenVar = len(varX)
      q = 0 
      while q &lt; lenVar:
          tarf = str(storage[i][q].encode('ascii', errors='ignore')).lstrip("b\'").rstrip("\'")
          try :
              ws.Cells(q+1,i+1).Value = (tarf)
          except pywintypes.com_error:
              print("Error")
              q +=1
          q += 1
      i += 1
  </code></pre>
  
  <p>The traceback I get is this :</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\LewTo002\Google Drive\Todd's Stuff\python\mailWords\current\mailWords2.py", line 65, in writeWords
      ws.Cells(q+1,i+1).Value = (tarf)
    File "C:\Users\LewTo002\AppData\Local\Programs\Python\Python35\lib\site-packages\win32com\client\__init__.py", line 474, in __setattr__
      self._oleobj_.Invoke(*(args + (value,) + defArgs))
  pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146777998), None)
  </code></pre>
  
  <p>During handling of the above exception, another exception occurred:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\LewTo002\AppData\Local\Programs\Python\Python35\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
      exec(codeObject, __main__.__dict__)
    File "C:\Users\LewTo002\Google Drive\Todd's Stuff\python\mailWords\current\mailWords2.py", line 100, in &lt;module&gt;
      writeWords(storage)
    File "C:\Users\LewTo002\Google Drive\Todd's Stuff\python\mailWords\current\mailWords2.py", line 66, in writeWords
      except pywintypes.com_error:
  NameError: name 'pywintypes' is not defined
  </code></pre>
  
  <p>I am used to seeing things like here ( <a href="https://docs.python.org/2/library/exceptions.html#exception-hierarchy" rel="nofollow">https://docs.python.org/2/library/exceptions.html#exception-hierarchy</a> ) and have been basing my method of writing the try/except off of here ( <a href="https://docs.python.org/3/tutorial/errors.html" rel="nofollow">https://docs.python.org/3/tutorial/errors.html</a> ) </p>
  
  <p>My question is how do I determine the error type that I am trying to catch based on the top portion of the traceback? </p>