Solved

_com_error

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

839 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