How to catch these exceptions individually?

前端 未结 2 778
逝去的感伤
逝去的感伤 2021-02-20 08:58

I am writing a Python program that interfaces with Quickbooks. When connecting to Quickbooks, depending on the problem, I might get one of two common exceptions:



        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 09:43

    Now pywintypes.error is BaseException.

    There is no need to from pywintypes import com_error.

    If you want to catch this exception. You can just catch BaseException

    except BaseException as e: # to catch pywintypes.error
        print(e.args)
    

    the exception's format likes this:

    (0, 'SetForegroundWindow', 'No error message is available')
    

    So If you want to examine the return code,use e.args[0] instead of e.exceptinfo[5]

提交回复
热议问题