MCPcopy Create free account
hub / github.com/mhammond/pywin32 / PyCom_BuildPyException

Function PyCom_BuildPyException

com/win32com/src/ErrorUtils.cpp:573–614  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////// Client Side Errors - translate a COM failure to a Python exception ///////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

571//
572////////////////////////////////////////////////////////////////////////
573PyObject *PyCom_BuildPyException(HRESULT errorhr, IUnknown *pUnk /* = NULL */, REFIID iid /* = IID_NULL */)
574{
575 PyObject *obEI = NULL;
576 TCHAR scodeStringBuf[512];
577 GetScodeString(errorhr, scodeStringBuf, sizeof(scodeStringBuf)/sizeof(scodeStringBuf[0]));
578
579#ifndef MS_WINCE // WINCE doesnt appear to have GetErrorInfo() - compiled, but doesnt link!
580 if (pUnk != NULL) {
581 assert(iid != IID_NULL); // If you pass an IUnknown, you should pass the specific IID.
582 // See if it supports error info.
583 ISupportErrorInfo *pSEI;
584 HRESULT hr;
585 Py_BEGIN_ALLOW_THREADS
586 hr = pUnk->QueryInterface(IID_ISupportErrorInfo, (void **)&pSEI);
587 if (SUCCEEDED(hr)) {
588 hr = pSEI->InterfaceSupportsErrorInfo(iid);
589 pSEI->Release(); // Finished with this object
590 }
591 Py_END_ALLOW_THREADS
592 if (SUCCEEDED(hr)) {
593 IErrorInfo *pEI;
594 Py_BEGIN_ALLOW_THREADS
595 hr=GetErrorInfo(0, &pEI);
596 Py_END_ALLOW_THREADS
597 if (hr==S_OK) {
598 obEI = PyCom_PyObjectFromIErrorInfo(pEI, errorhr);
599 PYCOM_RELEASE(pEI);
600 }
601 }
602 }
603#endif // MS_WINCE
604 if (obEI==NULL) {
605 obEI = Py_None;
606 Py_INCREF(Py_None);
607 }
608 PyObject *evalue = Py_BuildValue("iNOO", errorhr, PyWinObject_FromTCHAR(scodeStringBuf), obEI, Py_None);
609 Py_DECREF(obEI);
610
611 PyErr_SetObject(PyWinExc_COMError, evalue);
612 Py_XDECREF(evalue);
613 return NULL;
614}
615
616// Uses the HRESULT and an EXCEPINFO structure to create and
617// set a pythoncom.com_error.

Callers 15

DaoGetEngineFunction · 0.85
GetIDsOfNamesMethod · 0.85
GetTypeInfoMethod · 0.85
GetTypeInfoCountMethod · 0.85
CreateInstanceMethod · 0.85
LockServerMethod · 0.85
QueryInterfaceMethod · 0.85
univgw_CreateTearOffFunction · 0.85
ifFunction · 0.85
PyObject_FromRecordInfoFunction · 0.85

Calls 6

SUCCEEDEDFunction · 0.85
GetScodeStringFunction · 0.70
PyWinObject_FromTCHARFunction · 0.50
QueryInterfaceMethod · 0.45
ReleaseMethod · 0.45

Tested by 1

GetPagesMethod · 0.68