[Mono-list] Exception handling in Mono

Paolo Molaro lupus@ximian.com
Thu, 20 Feb 2003 18:55:37 +0100


On 02/19/03 Victor wrote:
> I'm working on a project related to Mono. In this project, I want to
> translate a external event (such as timer expires in OS) to an exception
> of Mono's managed code:

I dont think using exceptions is the best way to handle that kind of
stuff: you can have a thread wait on a semaphore or something like that.

> Timer expires-> ISR -> some function in Mono runtime -> exception thrown to 

Inside unmanged code, you can raise an exception with the function:

void mono_raise_exception        (MonoException *ex);

Just grep for it in the sources and you'll find lots of sample cases.

> I found some functions in /mono-0.19/mono/jit/exception.c and
> /mono-0.19/mono/jit/codegen-x86.c. I'm wondering if I can call
> mono_burg_emit_14() to throw the exception. But I don't know what the
> parameters s->code and thre->left->reg1 mean.

Definitely no. That is code internal to the implementation of the jit.
Using mono_raise_exception () is the API designed to do that.
Even better would be if you could keep the runtime in managed code and
throw the exception from there, using the normal C# syntax.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better