[Mono-dev] Re: C->C#, exceptions ...
Robert Jordan
robertj at gmx.net
Tue Mar 21 19:15:47 EST 2006
Hey,
> I modified your /mono/samples/embed/test-invoke.c
> I call a C# method, that throws an exception.
>
> 1) Can I obtain a Message (C#: exception.Message) ?
> 2) Can I obtain a type of exception. Smthg like get_type_name( MonObject
> *) ?
>
>
> MonoObject *exception = NULL;
> mono_runtime_invoke (fail, NULL, NULL, &exception);
> if (exception) {
> //I tried this, but no success:
> MonoClass *eklass = mono_object_get_class(exception);
> if (!eklass) {
> printf("eklass==NULL\n");
> }
> MonoClassField *Message =
Exception.Message is a property:
MonoProperty *prop;
MonoMethod *getter;
MonoString *msg;
prop = mono_class_get_property_from_name (eklass, "Message");
getter = mono_property_get_get_method (prop);
msg = mono_runtime_invoke (getter, exception, NULL, NULL);
> mono_class_get_field_from_name(klass, "Message");
> if (!Message) {
> printf("Message==NULL\n");
> }
> MonoString *msg;
>
> mono_field_get_value(exception, Message, &msg);
> }
>
> JV
Robert
More information about the Mono-devel-list
mailing list