2

My python program uses pythoncom (pythoncomxx.dll). I am sometimes getting a 'com_error' exception (which is fine) and I would like to catch it in an exception handler.

But when I try to do the following, the compiler complains that 'com_error' is unknown.

try:
  self.session.findById(tree_id).expandNode(node_id)
except com_error:
  print_exc()

I added the following to my imports, but this doesn't help: the statement 'from pythoncom import com_error' shows 'com_error' underlined in red

import pythoncom
import win32com.client
import time
from traceback import print_exc
from pythoncom import com_error

The 'solution' is to catch just all exceptions, but i want to catch only this one. How can I make the 'com_error' known to the program?

Thanks!

Mytzenka
  • 205
  • 1
  • 3
  • 16
  • Please post a Traceback of the exception (without the try/except). – wwii Sep 06 '17 at 14:24
  • Have you tried `except pythoncom.com_error as error` ?? https://stackoverflow.com/a/9203513/2823755, http://timgolden.me.uk/pywin32-docs/com_error.html – wwii Sep 06 '17 at 16:33
  • All examples of catching this show it as an attribute of `pythoncom` - https://github.com/SublimeText/Pywin32/search?utf8=%E2%9C%93&q=com_error&type= – wwii Sep 06 '17 at 16:40

1 Answers1

2

I don't know anything specifically about pythoncom, but it seems from google searching that the import is correct. Have you tried running the code even with the red underline present?

Because python is a dynamic language, not all errors underlined in red are actual errors. Some IDE's cannot inspect the contents of compiled extensions such as pythoncom.

Dustin Spicuzza
  • 694
  • 6
  • 12