[utils] Add mono_error_convert_to_exception.
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 9 Sep 2014 03:26:01 +0000 (23:26 -0400)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 9 Sep 2014 20:34:53 +0000 (16:34 -0400)
mono/utils/mono-error-internals.h
mono/utils/mono-error.c

index 672e2a75afadc0046a30614bd98fbcf88a2aad6c..ac2394fa41c3353715e59587460b5aecf41508af 100644 (file)
@@ -71,6 +71,9 @@ mono_error_set_from_loader_error (MonoError *error) MONO_INTERNAL;
 MonoException*
 mono_error_prepare_exception (MonoError *error, MonoError *error_out) MONO_INTERNAL;
 
+MonoException*
+mono_error_convert_to_exception (MonoError *error) MONO_INTERNAL;
+
 void
 mono_error_raise_exception (MonoError *error) MONO_INTERNAL;
 
index 57184d9d63b77aa229087562b07e2d1906794e85..63d6fcc00f862fa958321a6cd1cbb0045f9f6600 100644 (file)
@@ -636,20 +636,18 @@ mono_error_prepare_exception (MonoError *oerror, MonoError *error_out)
 }
 
 /*
-Raises the exception of @error.
-Does nothing if @error has a success error code.
-Aborts in case of a double fault. This happens when it can't recover from an error caused by trying
-to construct the first exception object.
-The error object @error is cleaned up. 
+Convert this MonoError to an exception if it's faulty or return NULL.
+The error object is cleant after.
 */
-void
-mono_error_raise_exception (MonoError *target_error)
+
+MonoException*
+mono_error_convert_to_exception (MonoError *target_error)
 {
        MonoError error;
        MonoException *ex;
 
        if (mono_error_ok (target_error))
-               return;
+               return NULL;
 
        ex = mono_error_prepare_exception (target_error, &error);
        if (!mono_error_ok (&error)) {
@@ -661,6 +659,21 @@ mono_error_raise_exception (MonoError *target_error)
                mono_error_cleanup (&error);
        }
        mono_error_cleanup (target_error);
+       return ex;
+}
 
-       mono_raise_exception (ex);      
+
+/*
+Raises the exception of @error.
+Does nothing if @error has a success error code.
+Aborts in case of a double fault. This happens when it can't recover from an error caused by trying
+to construct the first exception object.
+The error object @error is cleaned up. 
+*/
+void
+mono_error_raise_exception (MonoError *target_error)
+{
+       MonoException *ex = mono_error_convert_to_exception (target_error);
+       if (ex)
+               mono_raise_exception (ex);      
 }