|
|
|
date: Fri, 18 Jan 2008 14:23:07 +0100,
group: microsoft.public.platformsdk.com_ole
back
What is IErrorInfo::GetIID good for?
Hello newsgroup,
I'm intrigued what the method IErrorInfo::GetIID is good for. I have some
thoughts about this method but I'm not sure whether they're right or wrong.
AFAIK, COM exceptions are handled like Win32 GetLastError, e.g. that only the
last COM exception is stored by COM (if an older exception is never "caught" via
GetErrorInfo, a newer exception will replace the old exception). That's why it
can be quite difficult to determine whether an exception actually belongs to a
specific method invocation.
Let's suppose I have an IExampleInterface pointer to object A. If I invoke a
method on this interface pointer and get an HRESULT that indicates an exception,
I cannot be sure whether it was object A which threw the exception: It may be
the case that the implementation of A is not aware of exceptions, and the
exception that is currently stored by COM stems from an earlier method
invocation on a completely different object. As I understand, we can use the
ISupportErrorInfo interface to determine whether object A supports exceptions
over its IExampleInterface interface.
So far, so good.
If we have ruled out by above mentioned way that the exception is actually from
object A, there would be no need to check whether the exception really belongs
to the interface IExampleInterface. So what is IErrorInfo::GetIID good for?
Thanks in advance,
Stuart
date: Fri, 18 Jan 2008 14:23:07 +0100
author: Stuart Redmann
Re: What is IErrorInfo::GetIID good for?
Stuart Redmann wrote:
> AFAIK, COM exceptions are handled like Win32 GetLastError, e.g. that
> only the last COM exception is stored by COM (if an older exception
> is never "caught" via GetErrorInfo, a newer exception will replace
> the old exception). That's why it can be quite difficult to determine
> whether an exception actually belongs to a specific method invocation.
This is what ISupportErrorInfo is for. If you receive an error code from
a method call and want to get rich error information, you have to query
the object for ISupportErrorInfo and call InterfaceSupportsErrorInfo,
passing the IID of the interface whose method has just failed. If this
succeeds, then you know IErrorInfo object is in fact associated with the
most recent error. Otherwise, it's a stale object from some previous
error.
For this to work, an interface that claims to support rich error
information (via ISupportErrorInfo::InterfaceSupportsErrorInfo) has to
explicitly set or explicitly clear IErrorInfo whenever one of its
methods is about to return a failed HRESULT.
> So what
> is IErrorInfo::GetIID good for?
I don't see the point either.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
date: Fri, 18 Jan 2008 12:29:15 -0500
author: Igor Tandetnik
|
|