Marshal.ThrowExceptionForHR is broken?

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

Guest

I'm doing some interop work and I intended to use ThrowExceptionForHR to
convert HRESULTs into .Net exceptions. But ThrowExceptionForHR doesn't seem
to do anything as this simple C# illustrates:

static void Main(string[] args)
{
try
{
Console.WriteLine("before");
Marshal.ThrowExceptionForHR(5);
Console.WriteLine("after");
}
catch (Exception e)
{
Console.WriteLine("exception");
Console.WriteLine(e.Message);
}
}

I would expect to see the output "before;exception;message" but I actually
see "before;after". No exception is being thrown. Am I missing the point?
I'm using VS 2005.
 
Sorry, I've answered my own question. I'm confusing Win32 errors with
HRESULTs. e.g. 5 is "file not found" in win32 but is success when treated as
an HRESULT.
 
Back
Top