Solved

_com_error

Posted on 2000-03-27
2
1,491 Views
Last Modified: 2013-11-25
Hi All,
 I try to use try...catch construction in ATL COM object.
I'd like to use rich error, so I call Error("description",GUID_NULL,hr) in try block.
On catch, I get empty description.

try
{
 ...
 hr = pTest.CoCreateInstance(...
 if (FAILED(hr))
  _com_issue_errorex(Error("test.cpp (23)",GUID_NULL,hr));
 ...
 
}
catch(_com_error& e)
{
 CString s = (BSTR)e.Description();
}

1) I test e.Description(), but for this example is empty. Why?
When I call on try block wrapper method(another COM object - which sets description),
then description isn't empty.

Thanks
0
Comment
Question by:mizera
2 Comments
 

Accepted Solution

by:
sgold earned 100 total points
ID: 2660627
there isnt description all the time
tray e.ErrorMessage (); to get
the error
sgold
0
 

Author Comment

by:mizera
ID: 2662955
ErrorMessage() return description error code, but only for system code. I try to use own hresult and add file_line stamp.

I'd like to wrap catch block to macro. I found some way, but I dont't explain it.

Why (_com_error& e) haven't description, but IErrorInfo has?

#define __CATCH_COM_ERROR_EX(iid)
 }
 catch(_com_error& e)
 {
  CString _description = (BSTR)e.Description();
  if (_description.IsEmpty())
  {
   CComPtr<ISupportErrorInfo> pSEI;
   if (SUCCEEDED(QueryInterface(IID_ISupportErrorInfo,(void**)&pSEI)))
   {
    if (pSEI->InterfaceSupportsErrorInfo(IID_##iid) == S_OK)
    {
     CComPtr<IErrorInfo> pEI;
     if (GetErrorInfo(NULL,&pEI) == S_OK)
     {
      CComBSTR _bstr;
      pEI->GetDescription(&_bstr);
      _description = (BSTR)_bstr;
     }
    }
   }
  }

 ....
 e.g. return Error(_description,GUID_NULL,e.Error());
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question