[Mono-dev] Exception catching in C...
Robert Jordan
robertj at gmx.net
Thu Jan 4 15:05:20 EST 2007
Thomas Wiest wrote:
> On a related note, in my example project if I throw an exception that
> isn't handled (on purpose), the program prints the "Unhandled Exception"
> information but doesn't exit as expected. It just sits there. I've
> attached the example project. Sorry for the size, I tried to pare it
> down as much as possible. I also tried rewriting it in a more basic
> form, but then it didn't seem to have this problem. I've tried this on
> 1.1.13.8 (sled) and 1.2.2.1 (vmware image).
>
> Is this a bug, or am I doing something wrong?
The link in your previous mail was about p/invoke, where exceptions
can't be caught, but since you're embedding Mono, there is an easy and
documented way to handle exceptions:
mono_runtime_invoke's last argument is actually a MonoException**:
void call_person_ThrowException(person_class *person)
{
MonoObject *exception;
mono_runtime_invoke(person->methods->ThrowException,
person->object, NULL, &exception);
if (exception) do_something ();
}
I didn't look why your sample hangs, though.
Robert
More information about the Mono-devel-list
mailing list