[Mono-dev] New error handling framework for mono

Rodrigo Kumpera kumpera at gmail.com
Thu Aug 13 17:26:10 EDT 2009


The attached patch implements the basics for the new MonoError struct that
will be used for error handling in the runtime.
It has only the basics to support the current exceptions the runtime handle
for it's operation.

The usage is pretty much like the one in Paolo's email on the subject:

gboolean do_stuff () {
MonoError error;
mono_error_init (&error, 0);
runtime_function_that_might_fail (..., &error)
if (!mono_error_is_ok (&error))
  goto fail;
return TRUE;

mono_error_cleaup (&error);
return FALSE; //or raise an exception using mono_raise_exception
(mono_error_prepare_exception (&error));

The idea is to replace all error handling code with using this (loader
error, type exception_data and JIT's exception_type).

Still open is how this would be integrated on 2.6 and if functions should
error out if passed an already set error object.
The last point enables more concise code like:

MonoError error;
MonoType *type = ...;
mono_error_init (&error);
MonoClass *class = mono_class_from_mono_type (type, &error);
mono_class_init (class, &error);
MonoMethod *method = mono_class_get_method_from_name (class, "Invoke", 1,
if (!mono_error_ok (&error))
  return NULL;
return mono_runtime_invoke (method, NULL, params, NULL);

I left behind some aditional features I would like to add to help
development, like logging, signaling a breakpoint and
asserting if setting a second error to the same MonoError.

It would be a good time to hear the feeback on everyone about this,
specially embedders, since this will be the basis for
error handling of the new API comming in 2.8.

Please comment,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090813/12731f16/attachment.html 

More information about the Mono-devel-list mailing list