#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>
}
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;
- return create_exception_two_strings (klass, a1, a2);
+ klass = mono_class_load_from_name (image, name_space, name);
+
+ 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;
}
#include <mono/metadata/object.h>
#include <mono/metadata/gc-internals.h>
#include <mono/metadata/exception.h>
+#include <mono/metadata/exception-internals.h>
#include <mono/metadata/domain-internals.h>
#include "mono/metadata/metadata-internals.h"
#include "mono/metadata/class-internals.h"
{
MONO_REQ_GC_UNSAFE_MODE;
+ MonoError error;
MonoDomain *domain = vtable->domain;
MonoClass *klass = vtable->klass;
MonoException *ex;
full_name = g_strdup_printf ("%s.%s", klass->name_space, klass->name);
else
full_name = g_strdup (klass->name);
- ex = mono_get_exception_type_initialization (full_name, NULL);
+ ex = mono_get_exception_type_initialization_checked (full_name, NULL, &error);
g_free (full_name);
+ return_val_if_nok (&error, NULL);
}
return ex;
full_name = g_strdup_printf ("%s.%s", klass->name_space, klass->name);
else
full_name = g_strdup (klass->name);
- mono_error_set_exception_instance (error, mono_get_exception_type_initialization (full_name, exc));
+
+ MonoException *exc_to_throw = mono_get_exception_type_initialization_checked (full_name, exc, error);
g_free (full_name);
+ return_val_if_nok (error, FALSE);
+
+ mono_error_set_exception_instance (error, exc_to_throw);
MonoException *exc_to_store = mono_error_convert_to_exception (error);
/* What we really want to do here is clone the error object and store one copy in the
#include <mono/metadata/threads-types.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/exception.h>
+#include <mono/metadata/exception-internals.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/reflection-internals.h>
#include <mono/metadata/gc-internals.h>
if (!mono_object_isinst (obj, mono_defaults.exception_class)) {
non_exception = obj;
- obj = (MonoObject *)mono_get_exception_runtime_wrapped (obj);
+ obj = (MonoObject *)mono_get_exception_runtime_wrapped_checked (obj, &error);
+ mono_error_assert_ok (&error);
}
mono_ex = (MonoException*)obj;
static void
throw_exception (MonoObject *ex, gboolean rethrow)
{
+ MonoError error;
MonoJitTlsData *jit_tls = mono_get_jit_tls ();
MonoException *mono_ex;
- if (!mono_object_isinst (ex, mono_defaults.exception_class))
- mono_ex = mono_get_exception_runtime_wrapped (ex);
+ if (!mono_object_isinst (ex, mono_defaults.exception_class)) {
+ mono_ex = mono_get_exception_runtime_wrapped_checked (ex, &error);
+ mono_error_assert_ok (&error);
+ }
else
mono_ex = (MonoException*)ex;