Solved

_com_error

Posted on 2000-03-27
2
1,487 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference between String.subString() and String.subSequence() 6 177
File Watcher and Deleter with Email notification 5 92
only14 challenge 19 69
What is MicroStrategy.NET? 2 58
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now