2 * exception.c: Exception handling
5 * Paolo Molaro (lupus@ximian.com)
6 * Dietmar Maurer (dietmar@ximian.com)
7 * Dick Porter (dick@ximian.com)
8 * Miguel de Icaza (miguel@ximian.com)
10 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
11 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
12 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
17 #include <mono/metadata/exception.h>
18 #include <mono/metadata/exception-internals.h>
20 #include <mono/metadata/object-internals.h>
21 #include <mono/metadata/metadata-internals.h>
22 #include <mono/metadata/appdomain.h>
23 #include <mono/metadata/mono-debug.h>
24 #include <mono/utils/mono-error-internals.h>
27 #ifdef HAVE_EXECINFO_H
32 * mono_exception_from_name:
33 * @image: the Mono image where to look for the class
34 * @name_space: the namespace for the class
37 * Creates an exception of the given namespace/name class in the
40 * Returns: the initialized exception instance.
43 mono_exception_from_name (MonoImage *image, const char *name_space,
46 return mono_exception_from_name_domain (mono_domain_get (), image, name_space, name);
50 * mono_exception_from_name_domain:
51 * @domain: Domain where the return object will be created.
52 * @image: the Mono image where to look for the class
53 * @name_space: the namespace for the class
56 * Creates an exception object of the given namespace/name class on
59 * Returns: the initialized exception instance.
62 mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image,
63 const char* name_space, const char *name)
68 MonoDomain *caller_domain = mono_domain_get ();
70 klass = mono_class_load_from_name (image, name_space, name);
72 o = mono_object_new_checked (domain, klass, &error);
73 mono_error_assert_ok (&error);
75 if (domain != caller_domain)
76 mono_domain_set_internal (domain);
77 mono_runtime_object_init_checked (o, &error);
78 mono_error_assert_ok (&error);
80 if (domain != caller_domain)
81 mono_domain_set_internal (caller_domain);
83 return (MonoException *)o;
88 * mono_exception_from_token:
89 * @image: the Mono image where to look for the class
90 * @token: The type token of the class
92 * Creates an exception of the type given by @token.
94 * Returns: the initialized exception instance.
97 mono_exception_from_token (MonoImage *image, guint32 token)
103 klass = mono_class_get_checked (image, token, &error);
104 mono_error_assert_ok (&error);
106 o = mono_object_new_checked (mono_domain_get (), klass, &error);
107 mono_error_assert_ok (&error);
109 mono_runtime_object_init_checked (o, &error);
110 mono_error_assert_ok (&error);
112 return (MonoException *)o;
115 static MonoException *
116 create_exception_two_strings (MonoClass *klass, MonoString *a1, MonoString *a2, MonoError *error)
118 MonoDomain *domain = mono_domain_get ();
119 MonoMethod *method = NULL;
129 o = mono_object_new_checked (domain, klass, error);
130 mono_error_assert_ok (error);
133 while ((m = mono_class_get_methods (klass, &iter))) {
134 MonoMethodSignature *sig;
136 if (strcmp (".ctor", mono_method_get_name (m)))
138 sig = mono_method_signature (m);
139 if (sig->param_count != count)
142 if (sig->params [0]->type != MONO_TYPE_STRING)
144 if (count == 2 && sig->params [1]->type != MONO_TYPE_STRING)
153 mono_runtime_invoke_checked (method, o, args, error);
154 return_val_if_nok (error, NULL);
156 return (MonoException *) o;
160 * mono_exception_from_name_two_strings:
161 * @image: the Mono image where to look for the class
162 * @name_space: the namespace for the class
164 * @a1: first string argument to pass
165 * @a2: second string argument to pass
167 * Creates an exception from a constructor that takes two string
170 * Returns: the initialized exception instance.
173 mono_exception_from_name_two_strings (MonoImage *image, const char *name_space,
174 const char *name, MonoString *a1, MonoString *a2)
179 ret = mono_exception_from_name_two_strings_checked (image, name_space, name, a1, a2, &error);
180 mono_error_cleanup (&error);
185 * mono_exception_from_name_two_strings_checked:
186 * @image: the Mono image where to look for the class
187 * @name_space: the namespace for the class
189 * @a1: first string argument to pass
190 * @a2: second string argument to pass
191 * @error: set on error
193 * Creates an exception from a constructor that takes two string
196 * Returns: the initialized exception instance. On failure returns
197 * NULL and sets @error.
200 mono_exception_from_name_two_strings_checked (MonoImage *image, const char *name_space,
201 const char *name, MonoString *a1, MonoString *a2,
206 mono_error_init (error);
207 klass = mono_class_load_from_name (image, name_space, name);
209 return create_exception_two_strings (klass, a1, a2, error);
213 * mono_exception_from_name_msg:
214 * @image: the Mono image where to look for the class
215 * @name_space: the namespace for the class
217 * @msg: the message to embed inside the exception
219 * Creates an exception and initializes its message field.
221 * Returns: the initialized exception instance.
224 mono_exception_from_name_msg (MonoImage *image, const char *name_space,
225 const char *name, const char *msg)
229 ex = mono_exception_from_name (image, name_space, name);
232 MONO_OBJECT_SETREF (ex, message, mono_string_new (mono_object_get_domain ((MonoObject*)ex), msg));
238 * mono_exception_from_token_two_strings:
240 * Same as mono_exception_from_name_two_strings, but lookup the exception class using
244 mono_exception_from_token_two_strings (MonoImage *image, guint32 token,
245 MonoString *a1, MonoString *a2)
251 klass = mono_class_get_checked (image, token, &error);
252 mono_error_assert_ok (&error); /* FIXME handle the error. */
254 ret = create_exception_two_strings (klass, a1, a2, &error);
255 mono_error_raise_exception (&error); /* FIXME don't raise here */
261 * mono_get_exception_divide_by_zero:
263 * Returns: a new instance of the `System.DivideByZeroException`
266 mono_get_exception_divide_by_zero ()
268 return mono_exception_from_name (mono_get_corlib (), "System",
269 "DivideByZeroException");
273 * mono_get_exception_security:
275 * Returns: a new instance of the `System.Security.SecurityException`
278 mono_get_exception_security ()
280 return mono_exception_from_name (mono_get_corlib (), "System.Security",
281 "SecurityException");
285 * mono_get_exception_thread_abort:
287 * Returns: a new instance of the `System.Threading.ThreadAbortException`
290 mono_get_exception_thread_abort ()
292 return mono_exception_from_name (mono_get_corlib (), "System.Threading",
293 "ThreadAbortException");
297 * mono_get_exception_thread_interrupted:
299 * Returns: a new instance of the `System.Threading.ThreadInterruptedException`
302 mono_get_exception_thread_interrupted ()
304 return mono_exception_from_name (mono_get_corlib (), "System.Threading",
305 "ThreadInterruptedException");
309 * mono_get_exception_arithmetic:
311 * Returns: a new instance of the `System.ArithmeticException`
314 mono_get_exception_arithmetic ()
316 return mono_exception_from_name (mono_get_corlib (), "System",
317 "ArithmeticException");
321 * mono_get_exception_overflow:
323 * Returns: a new instance of the `System.OverflowException`
326 mono_get_exception_overflow ()
328 return mono_exception_from_name (mono_get_corlib (), "System",
329 "OverflowException");
333 * mono_get_exception_null_reference:
335 * Returns: a new instance of the `System.NullReferenceException`
338 mono_get_exception_null_reference ()
340 return mono_exception_from_name (mono_get_corlib (), "System",
341 "NullReferenceException");
345 * mono_get_exception_execution_engine:
346 * @msg: the message to pass to the user
348 * Returns: a new instance of the `System.ExecutionEngineException`
351 mono_get_exception_execution_engine (const char *msg)
353 return mono_exception_from_name_msg (mono_get_corlib (), "System", "ExecutionEngineException", msg);
357 * mono_get_exception_serialization:
358 * @msg: the message to pass to the user
360 * Returns: a new instance of the `System.Runtime.Serialization.SerializationException`
363 mono_get_exception_serialization (const char *msg)
365 return mono_exception_from_name_msg (mono_get_corlib (), "System.Runtime.Serialization", "SerializationException", msg);
369 * mono_get_exception_invalid_cast:
371 * Returns: a new instance of the `System.InvalidCastException`
374 mono_get_exception_invalid_cast ()
376 return mono_exception_from_name (mono_get_corlib (), "System", "InvalidCastException");
380 * mono_get_exception_invalid_operation:
381 * @msg: the message to pass to the user
383 * Returns: a new instance of the `System.InvalidOperationException`
386 mono_get_exception_invalid_operation (const char *msg)
388 return mono_exception_from_name_msg (mono_get_corlib (), "System",
389 "InvalidOperationException", msg);
393 * mono_get_exception_index_out_of_range:
395 * Returns: a new instance of the `System.IndexOutOfRangeException`
398 mono_get_exception_index_out_of_range ()
400 return mono_exception_from_name (mono_get_corlib (), "System",
401 "IndexOutOfRangeException");
405 * mono_get_exception_array_type_mismatch:
407 * Returns: a new instance of the `System.ArrayTypeMismatchException`
410 mono_get_exception_array_type_mismatch ()
412 return mono_exception_from_name (mono_get_corlib (), "System",
413 "ArrayTypeMismatchException");
417 * mono_get_exception_type_load:
418 * @class_name: the name of the class that could not be loaded
419 * @assembly_name: the assembly where the class was looked up.
421 * Returns: a new instance of the `System.TypeLoadException`
424 mono_get_exception_type_load (MonoString *class_name, char *assembly_name)
426 MonoString *s = assembly_name ? mono_string_new (mono_domain_get (), assembly_name) : mono_string_new (mono_domain_get (), "");
429 MonoException *ret = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System",
430 "TypeLoadException", class_name, s, &error);
431 mono_error_assert_ok (&error);
436 * mono_get_exception_not_implemented:
437 * @msg: the message to pass to the user
439 * Returns: a new instance of the `System.NotImplementedException`
442 mono_get_exception_not_implemented (const char *msg)
444 return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotImplementedException", msg);
448 * mono_get_exception_not_supported:
449 * @msg: the message to pass to the user
451 * Returns: a new instance of the `System.NotSupportedException`
454 mono_get_exception_not_supported (const char *msg)
456 return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotSupportedException", msg);
460 * mono_get_exception_missing_method:
461 * @class_name: the class where the lookup was performed.
462 * @member_name: the name of the missing method.
464 * Returns: a new instance of the `System.MissingMethodException`
467 mono_get_exception_missing_method (const char *class_name, const char *member_name)
469 MonoString *s1 = mono_string_new (mono_domain_get (), class_name);
470 MonoString *s2 = mono_string_new (mono_domain_get (), member_name);
473 MonoException *ret = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System",
474 "MissingMethodException", s1, s2, &error);
475 mono_error_assert_ok (&error);
480 * mono_get_exception_missing_field:
481 * @class_name: the class where the lookup was performed
482 * @member_name: the name of the missing method.
484 * Returns: a new instance of the `System.MissingFieldException`
487 mono_get_exception_missing_field (const char *class_name, const char *member_name)
489 MonoString *s1 = mono_string_new (mono_domain_get (), class_name);
490 MonoString *s2 = mono_string_new (mono_domain_get (), member_name);
493 MonoException *ret = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System",
494 "MissingFieldException", s1, s2, &error);
495 mono_error_assert_ok (&error);
500 * mono_get_exception_argument_null:
501 * @arg: the name of the argument that is null
503 * Returns: a new instance of the `System.ArgumentNullException`
506 mono_get_exception_argument_null (const char *arg)
510 ex = mono_exception_from_name (
511 mono_get_corlib (), "System", "ArgumentNullException");
514 MonoArgumentException *argex = (MonoArgumentException *)ex;
515 MONO_OBJECT_SETREF (argex, param_name, mono_string_new (mono_object_get_domain ((MonoObject*)ex), arg));
522 * mono_get_exception_argument:
523 * @arg: the name of the invalid argument.
525 * Returns: a new instance of the `System.ArgumentException`
528 mono_get_exception_argument (const char *arg, const char *msg)
532 ex = mono_exception_from_name_msg (
533 mono_get_corlib (), "System", "ArgumentException", msg);
536 MonoArgumentException *argex = (MonoArgumentException *)ex;
537 MONO_OBJECT_SETREF (argex, param_name, mono_string_new (mono_object_get_domain ((MonoObject*)ex), arg));
544 * mono_get_exception_argument_out_of_range:
545 * @arg: the name of the out of range argument.
547 * Returns: a new instance of the `System.ArgumentOutOfRangeException`
550 mono_get_exception_argument_out_of_range (const char *arg)
554 ex = mono_exception_from_name (
555 mono_get_corlib (), "System", "ArgumentOutOfRangeException");
558 MonoArgumentException *argex = (MonoArgumentException *)ex;
559 MONO_OBJECT_SETREF (argex, param_name, mono_string_new (mono_object_get_domain ((MonoObject*)ex), arg));
566 * mono_get_exception_thread_state:
567 * @msg: the message to present to the user
569 * Returns: a new instance of the `System.Threading.ThreadStateException`
572 mono_get_exception_thread_state (const char *msg)
574 return mono_exception_from_name_msg (
575 mono_get_corlib (), "System.Threading", "ThreadStateException", msg);
579 * mono_get_exception_io:
580 * @msg: the message to present to the user
582 * Returns: a new instance of the `System.IO.IOException`
585 mono_get_exception_io (const char *msg)
587 return mono_exception_from_name_msg (
588 mono_get_corlib (), "System.IO", "IOException", msg);
592 * mono_get_exception_file_not_found:
593 * @fname: the name of the file not found.
595 * Returns: a new instance of the `System.IO.FileNotFoundException`
598 mono_get_exception_file_not_found (MonoString *fname)
601 MonoException *ret = mono_exception_from_name_two_strings_checked (
602 mono_get_corlib (), "System.IO", "FileNotFoundException", fname, fname, &error);
603 mono_error_assert_ok (&error);
608 * mono_get_exception_file_not_found2:
609 * @msg: an informative message for the user.
610 * @fname: the name of the file not found.
612 * Returns: a new instance of the `System.IO.FileNotFoundException`
615 mono_get_exception_file_not_found2 (const char *msg, MonoString *fname)
617 MonoString *s = msg ? mono_string_new (mono_domain_get (), msg) : NULL;
620 MonoException *ret = mono_exception_from_name_two_strings_checked (
621 mono_get_corlib (), "System.IO", "FileNotFoundException", s, fname, &error);
622 mono_error_assert_ok (&error);
627 * mono_get_exception_type_initialization:
628 * @type_name: the name of the type that failed to initialize.
629 * @inner: the inner exception.
631 * Returns: a new instance of the `System.TypeInitializationException`
634 mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner)
637 MonoException *ret = mono_get_exception_type_initialization_checked (type_name, inner, &error);
638 if (!is_ok (&error)) {
639 mono_error_cleanup (&error);
647 mono_get_exception_type_initialization_checked (const gchar *type_name, MonoException *inner, MonoError *error)
655 klass = mono_class_load_from_name (mono_get_corlib (), "System", "TypeInitializationException");
657 mono_class_init (klass);
660 while ((method = mono_class_get_methods (klass, &iter))) {
661 if (!strcmp (".ctor", mono_method_get_name (method))) {
662 MonoMethodSignature *sig = mono_method_signature (method);
664 if (sig->param_count == 2 && sig->params [0]->type == MONO_TYPE_STRING && mono_class_from_mono_type (sig->params [1]) == mono_defaults.exception_class)
671 args [0] = mono_string_new (mono_domain_get (), type_name);
674 exc = mono_object_new_checked (mono_domain_get (), klass, error);
675 mono_error_assert_ok (error);
677 mono_runtime_invoke_checked (method, exc, args, error);
678 return_val_if_nok (error, NULL);
680 return (MonoException *) exc;
684 * mono_get_exception_synchronization_lock:
685 * @inner: the inner exception.
687 * Returns: a new instance of the `System.SynchronizationLockException`
690 mono_get_exception_synchronization_lock (const char *msg)
692 return mono_exception_from_name_msg (mono_get_corlib (), "System.Threading", "SynchronizationLockException", msg);
696 * mono_get_exception_cannot_unload_appdomain:
697 * @inner: the inner exception.
699 * Returns: a new instance of the `System.CannotUnloadAppDomainException`
702 mono_get_exception_cannot_unload_appdomain (const char *msg)
704 return mono_exception_from_name_msg (mono_get_corlib (), "System", "CannotUnloadAppDomainException", msg);
708 * mono_get_exception_appdomain_unloaded
710 * Returns: a new instance of the `System.AppDomainUnloadedException`
713 mono_get_exception_appdomain_unloaded (void)
715 return mono_exception_from_name (mono_get_corlib (), "System", "AppDomainUnloadedException");
719 * mono_get_exception_bad_image_format:
720 * @msg: an informative message for the user.
722 * Returns: a new instance of the `System.BadImageFormatException`
725 mono_get_exception_bad_image_format (const char *msg)
727 return mono_exception_from_name_msg (mono_get_corlib (), "System", "BadImageFormatException", msg);
731 * mono_get_exception_bad_image_format2:
732 * @msg: an informative message for the user.
733 * @fname: The full name of the file with the invalid image.
735 * Returns: a new instance of the `System.BadImageFormatException`
738 mono_get_exception_bad_image_format2 (const char *msg, MonoString *fname)
740 MonoString *s = msg ? mono_string_new (mono_domain_get (), msg) : NULL;
743 MonoException *ret = mono_exception_from_name_two_strings_checked (
744 mono_get_corlib (), "System", "BadImageFormatException", s, fname, &error);
745 mono_error_assert_ok (&error);
750 * mono_get_exception_stack_overflow:
752 * Returns: a new instance of the `System.StackOverflowException`
755 mono_get_exception_stack_overflow (void)
757 return mono_exception_from_name (mono_get_corlib (), "System", "StackOverflowException");
761 * mono_get_exception_out_of_memory:
763 * Returns: a new instance of the `System.OutOfMemoryException`
766 mono_get_exception_out_of_memory (void)
768 return mono_exception_from_name (mono_get_corlib (), "System", "OutOfMemoryException");
772 * mono_get_exception_field_access:
774 * Returns: a new instance of the `System.FieldAccessException`
777 mono_get_exception_field_access (void)
779 return mono_exception_from_name (mono_get_corlib (), "System", "FieldAccessException");
783 * mono_get_exception_field_access2:
784 * @msg: an informative message for the user.
786 * Returns: a new instance of the `System.FieldAccessException`
789 mono_get_exception_field_access_msg (const char *msg)
791 return mono_exception_from_name_msg (mono_get_corlib (), "System", "FieldAccessException", msg);
795 * mono_get_exception_method_access:
797 * Returns: a new instance of the `System.MethodAccessException`
800 mono_get_exception_method_access (void)
802 return mono_exception_from_name (mono_get_corlib (), "System", "MethodAccessException");
806 * mono_get_exception_method_access2:
807 * @msg: an informative message for the user.
809 * Returns: a new instance of the `System.MethodAccessException`
812 mono_get_exception_method_access_msg (const char *msg)
814 return mono_exception_from_name_msg (mono_get_corlib (), "System", "MethodAccessException", msg);
818 * mono_get_exception_reflection_type_load:
819 * @types: an array of types that were defined in the moduled loaded.
820 * @exceptions: an array of exceptions that were thrown during the type loading.
822 * Returns: a new instance of the `System.Reflection.ReflectionTypeLoadException`
825 mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
828 MonoException *ret = mono_get_exception_reflection_type_load_checked (types, exceptions, &error);
829 if (is_ok (&error)) {
830 mono_error_cleanup (&error);
838 mono_get_exception_reflection_type_load_checked (MonoArray *types, MonoArray *exceptions, MonoError *error)
846 klass = mono_class_load_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");
848 mono_class_init (klass);
850 /* Find the Type[], Exception[] ctor */
852 while ((method = mono_class_get_methods (klass, &iter))) {
853 if (!strcmp (".ctor", mono_method_get_name (method))) {
854 MonoMethodSignature *sig = mono_method_signature (method);
856 if (sig->param_count == 2 && sig->params [0]->type == MONO_TYPE_SZARRAY && sig->params [1]->type == MONO_TYPE_SZARRAY)
864 args [1] = exceptions;
866 exc = mono_object_new_checked (mono_domain_get (), klass, error);
867 mono_error_assert_ok (error);
869 mono_runtime_invoke_checked (method, exc, args, error);
870 return_val_if_nok (error, NULL);
872 return (MonoException *) exc;
876 mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
879 MonoException *ret = mono_get_exception_runtime_wrapped_checked (wrapped_exception, &error);
880 if (!is_ok (&error)) {
881 mono_error_cleanup (&error);
889 mono_get_exception_runtime_wrapped_checked (MonoObject *wrapped_exception, MonoError *error)
894 MonoDomain *domain = mono_domain_get ();
895 gpointer params [16];
897 klass = mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException");
899 o = mono_object_new_checked (domain, klass, error);
900 mono_error_assert_ok (error);
901 g_assert (o != NULL);
903 method = mono_class_get_method_from_name (klass, ".ctor", 1);
906 params [0] = wrapped_exception;
908 mono_runtime_invoke_checked (method, o, params, error);
909 return_val_if_nok (error, NULL);
911 return (MonoException *)o;
915 append_frame_and_continue (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data)
917 MonoDomain *domain = mono_domain_get ();
918 GString *text = (GString*)user_data;
921 char *msg = mono_debug_print_stack_frame (method, native_offset, domain);
922 g_string_append_printf (text, "%s\n", msg);
925 g_string_append_printf (text, "<unknown native frame 0x%x>\n", ip);
932 mono_exception_get_managed_backtrace (MonoException *exc)
936 text = g_string_new_len (NULL, 20);
938 if (!mono_get_eh_callbacks ()->mono_exception_walk_trace (exc, append_frame_and_continue, text))
939 g_string_append (text, "managed backtrace not available\n");
941 return g_string_free (text, FALSE);
945 mono_exception_get_native_backtrace (MonoException *exc)
947 #ifdef HAVE_BACKTRACE_SYMBOLS
949 MonoArray *arr = exc->native_trace_ips;
955 return g_strdup ("");
956 domain = mono_domain_get ();
957 len = mono_array_length (arr);
958 text = g_string_new_len (NULL, len * 20);
959 messages = backtrace_symbols (mono_array_addr (arr, gpointer, 0), len);
962 for (i = 0; i < len; ++i) {
963 gpointer ip = mono_array_get (arr, gpointer, i);
964 MonoJitInfo *ji = mono_jit_info_table_find (mono_domain_get (), (char *)ip);
966 char *msg = mono_debug_print_stack_frame (mono_jit_info_get_method (ji), (char*)ip - (char*)ji->code_start, domain);
967 g_string_append_printf (text, "%s\n", msg);
970 g_string_append_printf (text, "%s\n", messages [i]);
975 return g_string_free (text, FALSE);
977 return g_strdup ("");
982 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException *exc)
987 mono_set_pending_exception (mono_get_exception_argument_null ("exception"));
991 trace = mono_exception_get_native_backtrace (exc);
992 res = mono_string_new (mono_domain_get (), trace);
998 * mono_error_raise_exception:
999 * @target_error: the exception to raise
1001 * Raises the exception of @target_error.
1002 * Does nothing if @target_error has a success error code.
1003 * Aborts in case of a double fault. This happens when it can't recover from an error caused by trying
1004 * to construct the first exception object.
1005 * The error object @target_error is cleaned up.
1008 mono_error_raise_exception (MonoError *target_error)
1010 MonoException *ex = mono_error_convert_to_exception (target_error);
1012 mono_raise_exception (ex);
1016 * mono_error_set_pending_exception:
1020 * If @error is set, convert it to an exception and set the pending exception for the current icall.
1021 * Returns TRUE if @error was set, or FALSE otherwise, so that you can write:
1022 * if (mono_error_set_pending_exception (error)) {
1023 * { ... cleanup code ... }
1028 mono_error_set_pending_exception (MonoError *error)
1030 MonoException *ex = mono_error_convert_to_exception (error);
1032 mono_set_pending_exception (ex);