views:

20

answers:

2

Getting the (hex) error code from an IOException, or regular Exception!

Is this possible? i know it HAS a error code, (HResult) but the get accessor is private.

I would do some sort of ComException thing, but im not sure about the pros/cons of doing this, and if its even possible/the same.

A: 

Derive a specified class from Exception or IOException and expose the HRESULT value through an internal property.

class MyException:Exception
{
   internal GetHRResult()
   {
       return base.get_HResult();
   } 
   .....
}
robob
that would be good, except for i tried that and for some reason, (IOexceptionNameHere as MyException) returns null.
Tommy
looks like i cant cast the exception to a custom one.
Tommy
+2  A: 

Here it is suggested to call Marshall.GetHRForException.

jdv
that seems to work! :) I had actually just found that and returned to post my own answer but you beat me :P
Tommy