1d740908315c1542f38a27d53737b28d1c678e40
[mono.git] / mono / metadata / exception.c
1 /*
2  * exception.c: Exception handling
3  *
4  * Authors:
5  *      Paolo Molaro (lupus@ximian.com)
6  *      Dietmar Maurer (dietmar@ximian.com)
7  *      Dick Porter (dick@ximian.com)
8  *
9  * (C) 2001 Ximian, Inc.
10  */
11
12 #include <mono/metadata/exception.h>
13 #include <mono/metadata/class.h>
14
15 MonoObject*
16 mono_exception_from_name (MonoImage *image, const char *name_space,
17                           const char *name)
18 {
19         MonoClass *klass;
20         MonoObject *o;
21
22         klass = mono_class_from_name (image, name_space, name);
23
24         o = mono_object_new (klass);
25         g_assert (o != NULL);
26         
27         mono_runtime_object_init (o);
28
29         return o;
30 }
31
32 MonoObject*
33 get_exception_divide_by_zero ()
34 {
35         static MonoObject *ex = NULL;
36         if (ex)
37                 return ex;
38         ex = mono_exception_from_name (mono_defaults.corlib, "System",
39                                        "DivideByZeroException");
40         return ex;
41 }
42
43 MonoObject*
44 get_exception_security ()
45 {
46         static MonoObject *ex = NULL;
47         if (ex)
48                 return ex;
49         ex = mono_exception_from_name (mono_defaults.corlib, "System",
50                                        "SecurityException");
51         return ex;
52 }
53
54 MonoObject*
55 get_exception_arithmetic ()
56 {
57         static MonoObject *ex = NULL;
58         if (ex)
59                 return ex;
60         ex = mono_exception_from_name (mono_defaults.corlib, "System",
61                                        "ArithmeticException");
62         return ex;
63 }
64
65 MonoObject*
66 get_exception_overflow ()
67 {
68         static MonoObject *ex = NULL;
69         if (ex)
70                 return ex;
71         ex = mono_exception_from_name (mono_defaults.corlib, "System",
72                                        "OverflowException");
73         return ex;
74 }
75
76 MonoObject*
77 get_exception_null_reference ()
78 {
79         static MonoObject *ex = NULL;
80         if (ex)
81                 return ex;
82         ex = mono_exception_from_name (mono_defaults.corlib, "System",
83                                        "NullReferenceException");
84         return ex;
85 }
86
87 MonoObject*
88 get_exception_execution_engine ()
89 {
90         static MonoObject *ex = NULL;
91         if (ex)
92                 return ex;
93         ex = mono_exception_from_name (mono_defaults.corlib, "System",
94                                        "ExecutionEngineException");
95         return ex;
96 }
97
98 MonoObject*
99 get_exception_invalid_cast ()
100 {
101         static MonoObject *ex = NULL;
102         if (ex)
103                 return ex;
104         ex = mono_exception_from_name (mono_defaults.corlib, "System",
105                                        "InvalidCastException");
106         return ex;
107 }
108
109 MonoObject*
110 get_exception_index_out_of_range ()
111 {
112         static MonoObject *ex = NULL;
113         if (ex)
114                 return ex;
115         ex = mono_exception_from_name (mono_defaults.corlib, "System",
116                                        "IndexOutOfRangeException");
117         return ex;
118 }
119
120 MonoObject*
121 get_exception_array_type_mismatch ()
122 {
123         static MonoObject *ex = NULL;
124         if (ex)
125                 return ex;
126         ex = mono_exception_from_name (mono_defaults.corlib, "System",
127                                        "ArrayTypeMismatchException");
128         return ex;
129 }
130
131 MonoObject*
132 get_exception_missing_method ()
133 {
134         static MonoObject *ex = NULL;
135         if (ex)
136                 return ex;
137         ex = mono_exception_from_name (mono_defaults.corlib, "System",
138                                        "MissingMethodException");
139         return ex;
140 }
141