Solved

_com_error

Posted on 2000-03-27
2
1,498 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

738 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