#include <glib.h>
#include <mono/metadata/exception.h>
+#include <mono/metadata/exception-internals.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/metadata-internals.h>
klass = mono_class_load_from_name (image, name_space, name);
o = mono_object_new_checked (domain, klass, &error);
- g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */
+ mono_error_assert_ok (&error);
if (domain != caller_domain)
mono_domain_set_internal (domain);
- mono_runtime_object_init (o);
+ mono_runtime_object_init_checked (o, &error);
+ mono_error_assert_ok (&error);
+
if (domain != caller_domain)
mono_domain_set_internal (caller_domain);
MonoObject *o;
klass = mono_class_get_checked (image, token, &error);
- g_assert (mono_error_ok (&error)); /* FIXME handle the error. */
+ mono_error_assert_ok (&error);
o = mono_object_new_checked (mono_domain_get (), klass, &error);
- g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */
+ mono_error_assert_ok (&error);
- mono_runtime_object_init (o);
+ mono_runtime_object_init_checked (o, &error);
+ mono_error_assert_ok (&error);
return (MonoException *)o;
}
static MonoException *
-create_exception_two_strings (MonoClass *klass, MonoString *a1, MonoString *a2)
+create_exception_two_strings (MonoClass *klass, MonoString *a1, MonoString *a2, MonoError *error)
{
- MonoError error;
MonoDomain *domain = mono_domain_get ();
MonoMethod *method = NULL;
MonoObject *o;
if (a2 != NULL)
count++;
- o = mono_object_new_checked (domain, klass, &error);
- mono_error_assert_ok (&error);
+ o = mono_object_new_checked (domain, klass, error);
+ mono_error_assert_ok (error);
iter = NULL;
while ((m = mono_class_get_methods (klass, &iter))) {
args [0] = a1;
args [1] = a2;
- mono_runtime_invoke_checked (method, o, args, &error);
- mono_error_raise_exception (&error); /* FIXME don't raise here */
+ mono_runtime_invoke_checked (method, o, args, error);
+ return_val_if_nok (error, NULL);
return (MonoException *) o;
}
mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
const char *name, MonoString *a1, MonoString *a2)
{
- MonoClass *klass = mono_class_load_from_name (image, name_space, name);
+ MonoError error;
+ MonoClass *klass;
+ MonoException *ret;
+
+ klass = mono_class_load_from_name (image, name_space, name);
- return create_exception_two_strings (klass, a1, a2);
+ ret = create_exception_two_strings (klass, a1, a2, &error);
+ mono_error_raise_exception (&error); /* FIXME don't raise here */
+
+ return ret;
}
/**
MonoString *a1, MonoString *a2)
{
MonoError error;
- MonoClass *klass = mono_class_get_checked (image, token, &error);
- g_assert (mono_error_ok (&error)); /* FIXME handle the error. */
+ MonoClass *klass;
+ MonoException *ret;
+
+ klass = mono_class_get_checked (image, token, &error);
+ mono_error_assert_ok (&error); /* FIXME handle the error. */
+
+ ret = create_exception_two_strings (klass, a1, a2, &error);
+ mono_error_raise_exception (&error); /* FIXME don't raise here */
- return create_exception_two_strings (klass, a1, a2);
+ return ret;
}
/**
mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner)
{
MonoError error;
+ MonoException *ret = mono_get_exception_type_initialization_checked (type_name, inner, &error);
+ if (!is_ok (&error)) {
+ mono_error_cleanup (&error);
+ return NULL;
+ }
+
+ return ret;
+}
+
+MonoException *
+mono_get_exception_type_initialization_checked (const gchar *type_name, MonoException *inner, MonoError *error)
+{
MonoClass *klass;
gpointer args [2];
MonoObject *exc;
args [0] = mono_string_new (mono_domain_get (), type_name);
args [1] = inner;
- exc = mono_object_new_checked (mono_domain_get (), klass, &error);
- mono_error_assert_ok (&error);
- mono_runtime_invoke_checked (method, exc, args, &error);
- mono_error_raise_exception (&error); /* FIXME don't raise here */
+ exc = mono_object_new_checked (mono_domain_get (), klass, error);
+ mono_error_assert_ok (error);
+
+ mono_runtime_invoke_checked (method, exc, args, error);
+ return_val_if_nok (error, NULL);
return (MonoException *) exc;
}
mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
{
MonoError error;
+ MonoException *ret = mono_get_exception_reflection_type_load_checked (types, exceptions, &error);
+ if (is_ok (&error)) {
+ mono_error_cleanup (&error);
+ return NULL;
+ }
+
+ return ret;
+}
+
+MonoException *
+mono_get_exception_reflection_type_load_checked (MonoArray *types, MonoArray *exceptions, MonoError *error)
+{
MonoClass *klass;
gpointer args [2];
MonoObject *exc;
args [0] = types;
args [1] = exceptions;
- exc = mono_object_new_checked (mono_domain_get (), klass, &error);
- mono_error_assert_ok (&error);
+ exc = mono_object_new_checked (mono_domain_get (), klass, error);
+ mono_error_assert_ok (error);
- mono_runtime_invoke_checked (method, exc, args, &error);
- mono_error_raise_exception (&error); /* FIXME don't raise here */
+ mono_runtime_invoke_checked (method, exc, args, error);
+ return_val_if_nok (error, NULL);
return (MonoException *) exc;
}
mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
{
MonoError error;
+ MonoException *ret = mono_get_exception_runtime_wrapped_checked (wrapped_exception, &error);
+ if (!is_ok (&error)) {
+ mono_error_cleanup (&error);
+ return NULL;
+ }
+
+ return ret;
+}
+
+MonoException *
+mono_get_exception_runtime_wrapped_checked (MonoObject *wrapped_exception, MonoError *error)
+{
MonoClass *klass;
MonoObject *o;
MonoMethod *method;
klass = mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException");
- o = mono_object_new_checked (domain, klass, &error);
- g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */
+ o = mono_object_new_checked (domain, klass, error);
+ mono_error_assert_ok (error);
+ g_assert (o != NULL);
method = mono_class_get_method_from_name (klass, ".ctor", 1);
g_assert (method);
params [0] = wrapped_exception;
- mono_runtime_invoke_checked (method, o, params, &error);
- mono_error_raise_exception (&error); /* FIXME don't raise here */
+ mono_runtime_invoke_checked (method, o, params, error);
+ return_val_if_nok (error, NULL);
return (MonoException *)o;
}
mono_raise_exception (ex);
}
-void
+/**
+ * mono_error_set_pending_exception:
+ * @error: The error
+ *
+ *
+ * If @error is set, convert it to an exception and set the pending exception for the current icall.
+ * Returns TRUE if @error was set, or FALSE otherwise, so that you can write:
+ * if (mono_error_set_pending_exception (error)) {
+ * { ... cleanup code ... }
+ * return;
+ * }
+ */
+gboolean
mono_error_set_pending_exception (MonoError *error)
{
MonoException *ex = mono_error_convert_to_exception (error);
- if (ex)
+ if (ex) {
mono_set_pending_exception (ex);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
}