tags:

views:

21

answers:

1

I'm new in C# world. I have a COM server written in C++ and in some situation it returns a variant_t::missing(). When I try to receive that value in C#:

object a;
a = comServer.Value // Value returns missing

it throws a exception that I cannot event handle in C#.

How I should do?

+1  A: 

Wrap it in a try / catch:

try 
{
    object a = comServer.Value;
}
catch (Exception ex)
{
    // handle the error
}
Beaner
It doesn't work. The exception is finally catched by C++ code where the COM event is triggered.
I'm confused by your reference to an event. If you step through the code does the error occur when you execute object a = comServer.Value? Do you get anything back, even a null?
Beaner
The code in C++ of get_Value return variant_t::missing() but C# do not finish the execution of the line object a = comServer.Value so I cannot see anything in a because a exception is triggered in C++ code.C++ COM server triggers an event, in that event C# code executes this code and the exception is finally catched by C++ code ignoring the C# try catch section.