Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mono / utils / mono-error.c
index a59f2a123fb112f62d245290be57a7c909920f8b..2f83c8357d5281cba7d9699683d10907425241d0 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * mono-error.c: Error handling code
+/**
+ * \file
+ * Error handling code
  *
  * Authors:
  *     Rodrigo Kumpera    (rkumpera@novell.com)
@@ -101,10 +102,9 @@ mono_error_init_flags (MonoError *oerror, unsigned short flags)
 
 /**
  * mono_error_init:
- * @error: Pointer to MonoError struct to initialize
- *
- * Any function which takes a MonoError for purposes of reporting an error
- * is required to call either this or mono_error_init_flags on entry.
+ * \param error Pointer to \c MonoError struct to initialize
+ * Any function which takes a \c MonoError for purposes of reporting an error
+ * is required to call either this or \c mono_error_init_flags on entry.
  */
 void
 mono_error_init (MonoError *error)
@@ -297,7 +297,7 @@ mono_error_set_assembly_load_simple (MonoError *oerror, const char *assembly_nam
        if (refection_only)
                mono_error_set_assembly_load (oerror, assembly_name, "Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.");
        else
-               mono_error_set_assembly_load (oerror, assembly_name, "Could not load file or assembly or one of its dependencies.");
+               mono_error_set_assembly_load (oerror, assembly_name, "Could not load file or assembly '%s' or one of its dependencies.", assembly_name);
 }
 
 void
@@ -480,6 +480,16 @@ mono_error_set_exception_instance (MonoError *oerror, MonoException *exc)
        error->exn.instance_handle = mono_gchandle_new (exc ? &exc->object : NULL, FALSE);
 }
 
+void
+mono_error_set_exception_handle (MonoError *oerror, MonoExceptionHandle exc)
+{
+       MonoErrorInternal *error = (MonoErrorInternal*)oerror;
+
+       mono_error_prepare (error);
+       error->error_code = MONO_ERROR_EXCEPTION_INSTANCE;
+       error->exn.instance_handle = mono_gchandle_from_handle (MONO_HANDLE_CAST(MonoObject, exc), FALSE);
+}
+
 void
 mono_error_set_out_of_memory (MonoError *oerror, const char *msg_format, ...)
 {
@@ -574,7 +584,7 @@ mono_error_prepare_exception (MonoError *oerror, MonoError *error_out)
        MonoString *assembly_name = NULL, *type_name = NULL, *method_name = NULL, *field_name = NULL, *msg = NULL;
        MonoDomain *domain = mono_domain_get ();
 
-       mono_error_init (error_out);
+       error_init (error_out);
 
        switch (error->error_code) {
        case MONO_ERROR_NONE:
@@ -770,19 +780,17 @@ void
 mono_error_move (MonoError *dest, MonoError *src)
 {
        memcpy (dest, src, sizeof (MonoErrorInternal));
-       mono_error_init (src);
+       error_init (src);
 }
 
 /**
  * mono_error_box:
- * @ierror: The input error that will be boxed.
- * @image: The mempool of this image will hold the boxed error.
- *
- * Creates a new boxed error in the given mempool from MonoError.
- * It does not alter ierror, so you still have to clean it up with
- * mono_error_cleanup or mono_error_convert_to_exception or another such function.
- *
- * Returns the boxed error, or NULL if the mempool could not allocate.
+ * \param ierror The input error that will be boxed.
+ * \param image The mempool of this image will hold the boxed error.
+ * Creates a new boxed error in the given mempool from \c MonoError.
+ * It does not alter \p ierror, so you still have to clean it up with
+ * \c mono_error_cleanup or \c mono_error_convert_to_exception or another such function.
+ * \returns the boxed error, or NULL if the mempool could not allocate.
  */
 MonoErrorBoxed*
 mono_error_box (const MonoError *ierror, MonoImage *image)
@@ -823,16 +831,14 @@ mono_error_box (const MonoError *ierror, MonoImage *image)
 
 /**
  * mono_error_set_from_boxed:
- * @oerror: The error that will be set to the contents of the box.
- * @box: A mempool-allocated error.
- *
+ * \param oerror The error that will be set to the contents of the box.
+ * \param box A mempool-allocated error.
  * Sets the error condition in the oerror from the contents of the
  * given boxed error.  Does not alter the boxed error, so it can be
- * used in a future call to mono_error_set_from_boxed as needed.  The
- * oerror should've been previously initialized with mono_error_init,
+ * used in a future call to \c mono_error_set_from_boxed as needed.  The
+ * \p oerror should've been previously initialized with \c mono_error_init,
  * as usual.
- *
- * Returns TRUE on success or FALSE on failure.
+ * \returns TRUE on success or FALSE on failure.
  */
 gboolean
 mono_error_set_from_boxed (MonoError *oerror, const MonoErrorBoxed *box)