* 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>
return (MonoException *)o;
}
-/**
- * mono_exception_from_name_two_strings:
- * @image: the Mono image where to look for the class
- * @name_space: the namespace for the class
- * @name: class name
- * @a1: first string argument to pass
- * @a2: second string argument to pass
- *
- * Creates an exception from a constructor that takes two string
- * arguments.
- *
- * Returns: the initialized exception instance.
- */
-MonoException *
-mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
- const char *name, MonoString *a1, MonoString *a2)
+static MonoException *
+create_exception_two_strings (MonoClass *klass, MonoString *a1, MonoString *a2)
{
MonoDomain *domain = mono_domain_get ();
- MonoClass *klass;
MonoMethod *method = NULL;
MonoObject *o;
int count = 1;
if (a2 != NULL)
count++;
- klass = mono_class_from_name (image, name_space, name);
o = mono_object_new (domain, klass);
iter = NULL;
if (count == 2 && sig->params [1]->type != MONO_TYPE_STRING)
continue;
method = m;
+ break;
}
args [0] = a1;
return (MonoException *) o;
}
+/**
+ * mono_exception_from_name_two_strings:
+ * @image: the Mono image where to look for the class
+ * @name_space: the namespace for the class
+ * @name: class name
+ * @a1: first string argument to pass
+ * @a2: second string argument to pass
+ *
+ * Creates an exception from a constructor that takes two string
+ * arguments.
+ *
+ * Returns: the initialized exception instance.
+ */
+MonoException *
+mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
+ const char *name, MonoString *a1, MonoString *a2)
+{
+ MonoClass *klass = mono_class_from_name (image, name_space, name);
+
+ return create_exception_two_strings (klass, a1, a2);
+}
+
/**
* mono_exception_from_name_msg:
* @image: the Mono image where to look for the class
return ex;
}
+/**
+ * mono_exception_from_token_two_strings:
+ *
+ * Same as mono_exception_from_name_two_strings, but lookup the exception class using
+ * IMAGE and TOKEN.
+ */
+MonoException *
+mono_exception_from_token_two_strings (MonoImage *image, guint32 token,
+ MonoString *a1, MonoString *a2)
+{
+ MonoClass *klass = mono_class_get (image, token);
+
+ return create_exception_two_strings (klass, a1, a2);
+}
+
/**
* mono_get_exception_divide_by_zero:
*
return mono_exception_from_name (mono_get_corlib (), "System", "StackOverflowException");
}
+/**
+ * mono_get_exception_out_of_memory:
+ *
+ * Returns: a new instance of the System.OutOfMemoryException
+ */
+MonoException *
+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_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_reflection_type_load:
* @types: an array of types that were defined in the moduled loaded.