COM exceptions in C#?

  • Thread starter Thread starter Petar Popara
  • Start date Start date
P

Petar Popara

How can I catch COM exceptions (IErrorInfo) in C#? What should be inside
catch()?

An example:

try
{
....
}
catch(What goes here?)
{
....
}
 
check out the COMException on the MSDN website

Thank you. I've tried that and it catches the exception.

The only problem is that I got "Unspecified error" (e.Message()) insead of
error description I have set in my (VC++ 6) COM object. Why?
 
what should the error message contain? is 'Unspecified error' not the
expected message?

Ollie Riches
 
what should the error message contain? is 'Unspecified error' not the
expected message?

No, it was not expected message. I have set descriptive message text. :(
 
Are you receiving the expected HRESULT?

Yes. It is 0x80004005. Common text for this error code is "Unspecified
error", but I also specify my descriptive error message which C# (.Net)
ignores and prints common message.

I could show you the same exception handling code (that works fine) in C++
(not managed) if it would help.
 
This is JScript code that works fine:

try
{
myCOM.someMethod();
}
catch (e)
{
msg = "Exception: " + e.description;
msg += "\r\nException code: " + e.number;
}
 
Back
Top