Merge pull request #205 from m3rlinez/master
[mono.git] / mono / metadata / exception.c
index 4d1db36939a5aa2c3e65d13d6180bce78d7f9196..ee10668e20d247ff82d058cafc5dc8690204c455 100644 (file)
@@ -7,11 +7,13 @@
  *     Dick Porter     (dick@ximian.com)
  *      Miguel de Icaza (miguel@ximian.com)
  *
- * (C) 2001, 2002 Ximian, Inc.
+ * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
  */
 
 #include <mono/metadata/exception.h>
 #include <mono/metadata/object-internals.h>
+#include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/appdomain.h>
 #include <string.h>
 
@@ -51,13 +53,18 @@ mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image,
 {
        MonoClass *klass;
        MonoObject *o;
+       MonoDomain *caller_domain = mono_domain_get ();
 
        klass = mono_class_from_name (image, name_space, name);
 
        o = mono_object_new (domain, klass);
        g_assert (o != NULL);
-       
+
+       if (domain != caller_domain)
+               mono_domain_set_internal (domain);
        mono_runtime_object_init (o);
+       if (domain != caller_domain)
+               mono_domain_set_internal (caller_domain);
 
        return (MonoException *)o;
 }
@@ -585,7 +592,7 @@ mono_get_exception_type_initialization (const gchar *type_name, MonoException *i
  * mono_get_exception_synchronization_lock:
  * @inner: the inner exception.
  *
- * Returns: a new instance of the System.TypeInitializationException
+ * Returns: a new instance of the System.SynchronizationLockException
  */
 MonoException *
 mono_get_exception_synchronization_lock (const char *msg)
@@ -666,6 +673,52 @@ mono_get_exception_out_of_memory (void)
        return mono_exception_from_name (mono_get_corlib (), "System", "OutOfMemoryException");
 }
 
+/**
+ * mono_get_exception_field_access:
+ *
+ * Returns: a new instance of the System.FieldAccessException
+ */
+MonoException *
+mono_get_exception_field_access (void)
+{
+       return mono_exception_from_name (mono_get_corlib (), "System", "FieldAccessException");
+}
+
+/**
+ * mono_get_exception_field_access2:
+ * @msg: an informative message for the user.
+ *
+ * Returns: a new instance of the System.FieldAccessException
+ */
+MonoException *
+mono_get_exception_field_access_msg (const char *msg)
+{
+       return mono_exception_from_name_msg (mono_get_corlib (), "System", "FieldAccessException", msg);
+}
+
+/**
+ * mono_get_exception_method_access:
+ *
+ * Returns: a new instance of the System.MethodAccessException
+ */
+MonoException *
+mono_get_exception_method_access (void)
+{
+       return mono_exception_from_name (mono_get_corlib (), "System", "MethodAccessException");
+}
+
+/**
+ * mono_get_exception_method_access2:
+ * @msg: an informative message for the user.
+ *
+ * Returns: a new instance of the System.MethodAccessException
+ */
+MonoException *
+mono_get_exception_method_access_msg (const char *msg)
+{
+       return mono_exception_from_name_msg (mono_get_corlib (), "System", "MethodAccessException", msg);
+}
+
 /**
  * mono_get_exception_reflection_type_load:
  * @types: an array of types that were defined in the moduled loaded.
@@ -696,3 +749,14 @@ mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions
 
        return (MonoException *) exc;
 }
+
+MonoException *
+mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
+{
+       MonoRuntimeWrappedException *ex = (MonoRuntimeWrappedException*)
+               mono_exception_from_name (mono_get_corlib (), "System.Runtime.CompilerServices",
+                                                                 "RuntimeWrappedException");
+
+   MONO_OBJECT_SETREF (ex, wrapped_exception, wrapped_exception);
+   return (MonoException*)ex;
+}