Getting the Error Code from the Exception Object

  • Thread starter Thread starter Vikash Kumar Mitruka
  • Start date Start date
V

Vikash Kumar Mitruka

Hi all,

how can i get the unique error code that is associated with each
Exception.

there is one Property of Exception class named HResult. but that is
protected so i can not access it.

How can i do that. if anybody is having any idea than please do inform

Thanks
Vikash
 
Vikash Kumar Mitruka said:
Hi all,

how can i get the unique error code that is associated with each
Exception.

there is one Property of Exception class named HResult. but that is
protected so i can not access it.

How can i do that. if anybody is having any idea than please do inform

Thanks
Vikash

Vikash, not all exceptions have a unique error code associated with them.
HResult is not useful in the general case.

John Saunders
 
John said:
HResult is not useful in the general case.

To elaborate a bit, nearly all COM methods return an HRESULT and this is
the basis for COM error handling. Some common HRESULT values are here
[1]. For a more complete list, check out the winerror.h include file
that is normally included by a C++ COM project. COM objects are also
allowed to create custom HRESULT values.

When managed code calls into some COM code, it may get back a failing
HRESULT value. If the managed code can't handle the error, then it would
probably wrap the HRESULT up in a .NET exception and throw it. So for
the HResult value in an exception to be much value you'd probably need
to know what the managed code was doing, and what method on what COM
object was being called. Okay, unless it is something truly obvious like
E_OUTOFMEMORY.

And if the error didn't originate in a COM call, then the HResult is
going to be meaningless.

So what is the bigger problem that you're trying to solve?

Cheers,
Stuart

[1] http://msdn.microsoft.com/library/en-us/com/htm/error_899v.asp
 
Back
Top