* exception.c: Exception handling
*
* Authors:
- * Paolo Molaro (lupus@ximian.com)
- * Dietmar Maurer (dietmar@ximian.com)
- * Dick Porter (dick@ximian.com)
+ * Paolo Molaro (lupus@ximian.com)
+ * Dietmar Maurer (dietmar@ximian.com)
+ * Dick Porter (dick@ximian.com)
+ * Miguel de Icaza (miguel@ximian.com)
*
- * (C) 2001 Ximian, Inc.
+ * (C) 2001, 2002 Ximian, Inc.
*/
#include <mono/metadata/exception.h>
#include <mono/metadata/class.h>
#include <mono/metadata/appdomain.h>
+#include <string.h>
+/**
+ * mono_exception_from_name:
+ * @image: the Mono image where to look for the class
+ * @name_space: the namespace for the class
+ * @name: class name
+ *
+ * Creates an exception of the given namespace/name class.
+ *
+ * Returns: the initialized exception instance.
+ */
MonoException *
mono_exception_from_name (MonoImage *image, const char *name_space,
const char *name)
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.
+ */
+static MonoException *
+mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
+ const char *name, MonoString *a1, MonoString *a2)
+{
+ MonoDomain *domain = mono_domain_get ();
+ MonoClass *klass;
+ MonoMethod *method = NULL;
+ MonoObject *o;
+ int i;
+ gpointer args [2];
+
+ klass = mono_class_from_name (image, name_space, name);
+ o = mono_object_new (domain, klass);
+
+ for (i = 0; i < klass->method.count; ++i) {
+ MonoMethodSignature *sig;
+
+ if (strcmp (".ctor", klass->methods [i]->name))
+ continue;
+ sig = klass->methods [i]->signature;
+ if (sig->param_count != 2)
+ continue;
+
+ if (sig->params [0]->type != MONO_TYPE_STRING ||
+ sig->params [1]->type != MONO_TYPE_STRING)
+ continue;
+ method = klass->methods [i];
+ }
+
+ args [0] = a1;
+ args [1] = a2;
+ mono_runtime_invoke (method, o, args, NULL);
+ return (MonoException *) o;
+}
+
MonoException *
mono_get_exception_divide_by_zero ()
{
return(ex);
}
+MonoException *
+mono_get_exception_file_not_found (MonoString *fname)
+{
+ return mono_exception_from_name_two_strings (
+ mono_defaults.corlib, "System.IO", "FileNotFoundException", fname, fname);
+}