Marshal.ThrowExceptionForHR is broken?

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top