Merge pull request #2698 from esdrubal/iosxmlarray
[mono.git] / mono / metadata / exception.c
index f84219678aa08cece25b0768cfea5ac1e62aa445..e2c45aca38bbc615c7547112df6253a7475560bb 100644 (file)
@@ -68,11 +68,13 @@ mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image,
        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);
 
@@ -97,12 +99,13 @@ mono_exception_from_token (MonoImage *image, guint32 token)
        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;
 }
@@ -963,11 +966,27 @@ mono_error_raise_exception (MonoError *target_error)
                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;
+       }
 }