3434static MonoUnhandledExceptionFunc unhandled_exception_hook = NULL ;
3535static gpointer unhandled_exception_hook_data = NULL ;
3636
37+ static MonoExceptionHandle
38+ mono_exception_new_by_name_domain (MonoDomain * domain , MonoImage * image ,
39+ const char * name_space , const char * name , MonoError * error );
40+
41+ /**
42+ * mono_exception_new_by_name:
43+ * \param image the Mono image where to look for the class
44+ * \param name_space the namespace for the class
45+ * \param name class name
46+ *
47+ * Creates an exception of the given namespace/name class in the
48+ * current domain.
49+ *
50+ * \returns the initialized exception instance.
51+ */
52+ static MonoExceptionHandle
53+ mono_exception_new_by_name (MonoImage * image , const char * name_space , const char * name , MonoError * error )
54+ {
55+ return mono_exception_new_by_name_domain (mono_domain_get (), image , name_space , name , error );
56+ }
57+
3758/**
3859 * mono_exception_from_name:
3960 * \param image the Mono image where to look for the class
@@ -52,6 +73,48 @@ mono_exception_from_name (MonoImage *image, const char *name_space,
5273 return mono_exception_from_name_domain (mono_domain_get (), image , name_space , name );
5374}
5475
76+ /**
77+ * mono_exception_new_by_name_domain:
78+ * \param domain Domain where the return object will be created.
79+ * \param image the Mono image where to look for the class
80+ * \param name_space the namespace for the class
81+ * \param name class name
82+ *
83+ * Creates an exception object of the given namespace/name class on
84+ * the given domain.
85+ *
86+ * \returns the initialized exception instance.
87+ */
88+ static MonoExceptionHandle
89+ mono_exception_new_by_name_domain (MonoDomain * domain , MonoImage * image ,
90+ const char * name_space , const char * name , MonoError * error )
91+ {
92+ HANDLE_FUNCTION_ENTER ()
93+
94+ MonoDomain * const caller_domain = mono_domain_get ();
95+
96+ MonoClass * const klass = mono_class_load_from_name (image , name_space , name );
97+
98+ MonoObjectHandle o = MONO_HANDLE_NEW (MonoObject , mono_object_new_checked (domain , klass , error ));
99+ goto_if_nok (error , return_null );
100+
101+ if (domain != caller_domain )
102+ mono_domain_set_internal (domain );
103+
104+ mono_runtime_object_init_handle (o , error );
105+ mono_error_assert_ok (error );
106+
107+ // Restore domain in success and error path.
108+ if (domain != caller_domain )
109+ mono_domain_set_internal (caller_domain );
110+
111+ goto_if_ok (error , exit );
112+ return_null :
113+ MONO_HANDLE_ASSIGN (o , NULL );
114+ exit :
115+ HANDLE_FUNCTION_RETURN_REF (MonoException , o );
116+ }
117+
55118/**
56119 * mono_exception_from_name_domain:
57120 * \param domain Domain where the return object will be created.
@@ -215,6 +278,40 @@ mono_exception_from_name_two_strings_checked (MonoImage *image, const char *name
215278 return create_exception_two_strings (klass , a1 , a2 , error );
216279}
217280
281+ /**
282+ * mono_exception_new_by_name_msg:
283+ * \param image the Mono image where to look for the class
284+ * \param name_space the namespace for the class
285+ * \param name class name
286+ * \param msg the message to embed inside the exception
287+ *
288+ * Creates an exception and initializes its message field.
289+ *
290+ * \returns the initialized exception instance.
291+ */
292+ MonoExceptionHandle
293+ mono_exception_new_by_name_msg (MonoImage * image , const char * name_space ,
294+ const char * name , const char * msg , MonoError * error )
295+ {
296+ HANDLE_FUNCTION_ENTER ()
297+
298+ MonoExceptionHandle ex = mono_exception_new_by_name (image , name_space , name , error );
299+ goto_if_nok (error , return_null );
300+
301+ if (msg ) {
302+ MonoStringHandle msg_str = mono_string_new_handle (MONO_HANDLE_DOMAIN (ex ), msg , error );
303+ // FIXME? Maybe just ignore this error, the exception is close to correct.
304+ goto_if_nok (error , return_null );
305+ // ex->message = msg_str;
306+ MONO_HANDLE_SET (ex , message , msg_str );
307+ }
308+ goto exit ;
309+ return_null :
310+ MONO_HANDLE_ASSIGN (ex , NULL );
311+ exit :
312+ HANDLE_FUNCTION_RETURN_REF (MonoException , ex )
313+ }
314+
218315/**
219316 * mono_exception_from_name_msg:
220317 * \param image the Mono image where to look for the class
@@ -304,6 +401,16 @@ mono_get_exception_security ()
304401 "SecurityException" );
305402}
306403
404+ /**
405+ * mono_exception_new_thread_abort:
406+ * \returns a new instance of the \c System.Threading.ThreadAbortException
407+ */
408+ MonoExceptionHandle
409+ mono_exception_new_thread_abort (MonoError * error )
410+ {
411+ return mono_exception_new_by_name (mono_get_corlib (), "System.Threading" , "ThreadAbortException" , error );
412+ }
413+
307414/**
308415 * mono_get_exception_thread_abort:
309416 * \returns a new instance of the \c System.Threading.ThreadAbortException
@@ -315,6 +422,16 @@ mono_get_exception_thread_abort ()
315422 "ThreadAbortException" );
316423}
317424
425+ /**
426+ * mono_exception_new_thread_interrupted:
427+ * \returns a new instance of the \c System.Threading.ThreadInterruptedException
428+ */
429+ MonoExceptionHandle
430+ mono_exception_new_thread_interrupted (MonoError * error )
431+ {
432+ return mono_exception_new_by_name (mono_get_corlib (), "System.Threading" , "ThreadInterruptedException" , error );
433+ }
434+
318435/**
319436 * mono_get_exception_thread_interrupted:
320437 * \returns a new instance of the \c System.Threading.ThreadInterruptedException
@@ -403,6 +520,12 @@ mono_get_exception_invalid_operation (const char *msg)
403520 "InvalidOperationException" , msg );
404521}
405522
523+ MonoExceptionHandle
524+ mono_exception_new_invalid_operation (const char * msg , MonoError * error )
525+ {
526+ return mono_exception_new_by_name_msg (mono_get_corlib (), "System" , "InvalidOperationException" , msg , error );
527+ }
528+
406529/**
407530 * mono_get_exception_index_out_of_range:
408531 * \returns a new instance of the \c System.IndexOutOfRangeException
@@ -589,6 +712,12 @@ mono_get_exception_argument_out_of_range (const char *arg)
589712 * \param msg the message to present to the user
590713 * \returns a new instance of the \c System.Threading.ThreadStateException
591714 */
715+ MonoExceptionHandle
716+ mono_exception_new_thread_state (const char * msg , MonoError * error )
717+ {
718+ return mono_exception_new_by_name_msg (mono_get_corlib (), "System.Threading" , "ThreadStateException" , msg , error );
719+ }
720+
592721MonoException *
593722mono_get_exception_thread_state (const char * msg )
594723{
@@ -850,10 +979,7 @@ mono_get_exception_reflection_type_load (MonoArray *types_raw, MonoArray *except
850979 if (is_ok (error )) {
851980 mono_error_cleanup (error );
852981 ret = MONO_HANDLE_CAST (MonoException , NULL_HANDLE );
853- goto leave ;
854982 }
855-
856- leave :
857983 HANDLE_FUNCTION_RETURN_OBJ (ret );
858984
859985}
0 commit comments