title: How to determine correct exception class
body: <p>I'm using Python WMI module to collect hardware information from a Windows system.  This line raises an exception:</p>
  <pre><code>numa = c.Win32_PerfFormattedData_PerfOS_NUMANodeMemory()
  Traceback (most recent call last):
    File &quot;wmi.py&quot;, line 1209, in __getattr__
    File &quot;wmi.py&quot;, line 1220, in _cached_classes
    File &quot;&lt;COMObject winmgmts:&gt;&quot;, line 3, in Get
    File &quot;win32com\client\dynamic.py&quot;, line 287, in _ApplyTypes_
  pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemServicesEx', None, None, 0, -1073738817), None)
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;health_check.py&quot;, line 1138, in &lt;module&gt;
    File &quot;health_check.py&quot;, line 1121, in main
    File &quot;health_check.py&quot;, line 228, in hardware_info
    File &quot;wmi.py&quot;, line 1211, in __getattr__
    File &quot;win32com\client\dynamic.py&quot;, line 527, in __getattr__
  AttributeError: winmgmts:.Win32_PerfFormattedData_PerfOS_NUMANodeMemory
  </code></pre>
  <p>So I tried to catch it like this:</p>
  <pre><code>import pywintypes.com_error
  try:
      numa = c.Win32_PerfFormattedData_PerfOS_NUMANodeMemory()
  
  except pywintypes.com_error:
      logger.error('Failed to read NUMA status.')
  </code></pre>
  <p>But the import fails:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;health_check.py&quot;, line 20, in &lt;module&gt;
  ModuleNotFoundError: No module named 'pywintypes.com_error'; 'pywintypes' is not a package
  [9464] Failed to execute script health_check
  </code></pre>
  <p>I tried not importing the <code>com_error</code> class but that didn't work either.  How can I find out the correct import to catch this type of exception?  After importing <code>wmi</code> the module exists here:</p>
  <pre><code>&gt;&gt;&gt; sys.modules['pywintypes']
  &lt;module 'pywintypes' (C:\WINDOWS\SYSTEM32\pywintypes37.dll)&gt;
  &gt;&gt;&gt; sys.modules['pywintypes'].com_error
  &lt;class 'pywintypes.com_error'&gt;
  </code></pre>