HRESULTs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I've been asked to write some code that only logs "serious exceptions" (a
client... long story). I'm a somewhat young programmer and started w/ .net so
I haven't been exposed to Com and Hresults before.

My question is: I know that all .net exceptions have an HRESULT protected
property. Is it true that there's a relationship between an error/exceptions
"level of severity" and its HResult value?

For instance:
The HResult for a common error such as System.NullReferenceException is:
0x80004003 (Reflector has the integer value as: 2147467261)

The HResult for an exception that signifies serious trouble such as
System.ExecutionEngineException is: 0x80131506. Aka 2146233082

Would it be possible for me to define an HRESULT "threshold" and log all
exceptions that are above or below such a value? Or is there no
relationship between severity and an exception's HRESULT value? I suppose
the other alternative is to use multiple exception filters but assuming that
my "relationship" assumption is correct the user one if statement would be
more simple and scalable.

I know the Logging Block in the new Enterprise Library can do this but I’ve
been asked to implement a solution in the next couple of days and haven’t
delved far enough into the Enterprise library to use it in a real project yet.
 
Would it be possible for me to define an HRESULT "threshold" and log all
exceptions that are above or below such a value? Or is there no
relationship between severity and an exception's HRESULT value?

You can only tell the severity from the two high bits in the value.
The following comment from the WinError.h header file in the Platform
SDK describes the meaning of the bits in a HRESULT value.

//
// Values are 32 bit values layed out as follows:
//
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
// +---+-+-+-----------------------+-------------------------------+
// |Sev|C|R| Facility | Code |
// +---+-+-+-----------------------+-------------------------------+
//
// where
//
// Sev - is the severity code
//
// 00 - Success
// 01 - Informational
// 10 - Warning
// 11 - Error
//
// C - is the Customer code flag
//
// R - is a reserved bit
//
// Facility - is the facility code
//
// Code - is the facility's status code



Mattias
 
Back
Top