2 * exception.c: Exception handling
5 * Paolo Molaro (lupus@ximian.com)
6 * Dietmar Maurer (dietmar@ximian.com)
7 * Dick Porter (dick@ximian.com)
9 * (C) 2001 Ximian, Inc.
12 #include <mono/metadata/exception.h>
13 #include <mono/metadata/class.h>
14 #include <mono/metadata/appdomain.h>
17 mono_exception_from_name (MonoImage *image, const char *name_space,
20 MonoDomain *domain = mono_domain_get ();
24 klass = mono_class_from_name (image, name_space, name);
26 o = mono_object_new (domain, klass);
29 mono_runtime_object_init (o);
31 return (MonoException *)o;
35 mono_get_exception_divide_by_zero ()
37 return mono_exception_from_name (mono_defaults.corlib, "System",
38 "DivideByZeroException");
42 mono_get_exception_security ()
44 return mono_exception_from_name (mono_defaults.corlib, "System",
49 mono_get_exception_arithmetic ()
51 return mono_exception_from_name (mono_defaults.corlib, "System",
52 "ArithmeticException");
56 mono_get_exception_overflow ()
58 return mono_exception_from_name (mono_defaults.corlib, "System",
63 mono_get_exception_null_reference ()
65 return mono_exception_from_name (mono_defaults.corlib, "System",
66 "NullReferenceException");
70 mono_get_exception_execution_engine ()
72 return mono_exception_from_name (mono_defaults.corlib, "System",
73 "ExecutionEngineException");
77 mono_get_exception_invalid_cast ()
79 return mono_exception_from_name (mono_defaults.corlib, "System",
80 "InvalidCastException");
84 mono_get_exception_index_out_of_range ()
86 return mono_exception_from_name (mono_defaults.corlib, "System",
87 "IndexOutOfRangeException");
91 mono_get_exception_array_type_mismatch ()
93 return mono_exception_from_name (mono_defaults.corlib, "System",
94 "ArrayTypeMismatchException");
98 mono_get_exception_type_load ()
100 return mono_exception_from_name (mono_defaults.corlib, "System",
101 "TypeLoadException");
105 mono_get_exception_not_implemented ()
107 return mono_exception_from_name (mono_defaults.corlib, "System",
108 "NotImplementedException");
112 mono_get_exception_missing_method ()
114 return mono_exception_from_name (mono_defaults.corlib, "System",
115 "MissingMethodException");
119 mono_get_exception_argument_null (MonoDomain *domain, const guchar *arg)
123 ex = (MonoException *)mono_exception_from_name (
124 mono_defaults.corlib, "System", "ArgumentNullException");
127 ((MonoArgumentException *)ex)->param_name =
128 mono_string_new (domain, arg);
134 mono_get_exception_argument (MonoDomain *domain, const guchar *arg, const guchar *msg)
138 ex = (MonoException *)mono_exception_from_name (
139 mono_defaults.corlib, "System", "ArgumentException");
142 ex->message = mono_string_new (domain, msg);
145 ((MonoArgumentException *)ex)->param_name =
146 mono_string_new (domain, arg);
152 mono_get_exception_io (MonoDomain *domain, const guchar *msg)
156 ex=(MonoException *)mono_exception_from_name (
157 mono_defaults.corlib, "System.IO", "IOException");
159 ex->message=mono_string_new (domain, msg);