Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 30 Sep 2008 10:54:05 -0700,    group: microsoft.public.xml        back       


How to catch an exception thrown by MSXML?   
Consider this function:

BOOL GetSingleNodeV(const MSXML2::IXMLDOMDocumentPtr pXMLDoc, const CString 
&strPath, CString &StrValue)
{
	BOOL bRetCode=FALSE;

	BSTR bstrQstr = strPath.AllocSysString();
	IXMLDOMNodePtr o;
	o = pXMLDoc->selectSingleNode( bstrQstr);
	if (o!=NULL)
	{
		HRESULT hr=o->get_text(&bstrQstr);
		if (hr==S_OK)
		{
			StrValue = bstrQstr;
			bRetCode = TRUE;
		}
		else
		{
			StrValue="";
		}
	}
	//o->Release();
	SysFreeString(bstrQstr);

	return bRetCode;
}

Call to selectSingleNode sometimes works as expected but sometimes it throws 
an exception. How can I extract additional information about this exception?
date: Tue, 30 Sep 2008 10:54:05 -0700   author:   JoeSchmoe112

Re: How to catch an exception thrown by MSXML?   
"JoeSchmoe112"  wrote in message 
news:41619253-B8E2-4EE4-9D7C-C1F03086B966@microsoft.com...
> Consider this function:
>
> BOOL GetSingleNodeV(const MSXML2::IXMLDOMDocumentPtr pXMLDoc, const 
> CString
> &strPath, CString &StrValue)
> {
> BOOL bRetCode=FALSE;
>
> BSTR bstrQstr = strPath.AllocSysString();
> IXMLDOMNodePtr o;
> o = pXMLDoc->selectSingleNode( bstrQstr);
> if (o!=NULL)
> {
> HRESULT hr=o->get_text(&bstrQstr);
> if (hr==S_OK)
> {
> StrValue = bstrQstr;
> bRetCode = TRUE;
> }
> else
> {
> StrValue="";
> }
> }
> //o->Release();
> SysFreeString(bstrQstr);
>
> return bRetCode;
> }
>
> Call to selectSingleNode sometimes works as expected but sometimes it 
> throws
> an exception. How can I extract additional information about this 
> exception?

You can access details about errors generated by COM components with the 
_com_error exception:-

try
{
  // your code
}
catch (_com_error &e)
{
  // here you can use _com_error members such as e.Description()
}


-- 
Anthony Jones - MVP ASP/ASP.NET
date: Wed, 1 Oct 2008 21:40:11 +0100   author:   Anthony Jones

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us