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
)
249 ret
= mono_exception_from_token_two_strings_checked (image
, token
, a1
, a2
, &error
);
250 mono_error_cleanup (&error
);
255 * mono_exception_from_token_two_strings_checked:
257 * Same as mono_exception_from_name_two_strings, but lookup the exception class using
261 mono_exception_from_token_two_strings_checked (MonoImage
*image
, guint32 token
,
262 MonoString
*a1
, MonoString
*a2
,
267 mono_error_init (error
);
269 klass
= mono_class_get_checked (image
, token
, error
);
270 mono_error_assert_ok (error
); /* FIXME handle the error. */
272 return create_exception_two_strings (klass
, a1
, a2
, error
);
276 * mono_get_exception_divide_by_zero:
278 * Returns: a new instance of the `System.DivideByZeroException`
281 mono_get_exception_divide_by_zero ()
283 return mono_exception_from_name (mono_get_corlib (), "System",
284 "DivideByZeroException");
288 * mono_get_exception_security:
290 * Returns: a new instance of the `System.Security.SecurityException`
293 mono_get_exception_security ()
295 return mono_exception_from_name (mono_get_corlib (), "System.Security",
296 "SecurityException");
300 * mono_get_exception_thread_abort:
302 * Returns: a new instance of the `System.Threading.ThreadAbortException`
305 mono_get_exception_thread_abort ()
307 return mono_exception_from_name (mono_get_corlib (), "System.Threading",
308 "ThreadAbortException");
312 * mono_get_exception_thread_interrupted:
314 * Returns: a new instance of the `System.Threading.ThreadInterruptedException`
317 mono_get_exception_thread_interrupted ()
319 return mono_exception_from_name (mono_get_corlib (), "System.Threading",
320 "ThreadInterruptedException");
324 * mono_get_exception_arithmetic:
326 * Returns: a new instance of the `System.ArithmeticException`
329 mono_get_exception_arithmetic ()
331 return mono_exception_from_name (mono_get_corlib (), "System",
332 "ArithmeticException");
336 * mono_get_exception_overflow:
338 * Returns: a new instance of the `System.OverflowException`
341 mono_get_exception_overflow ()
343 return mono_exception_from_name (mono_get_corlib (), "System",
344 "OverflowException");
348 * mono_get_exception_null_reference:
350 * Returns: a new instance of the `System.NullReferenceException`
353 mono_get_exception_null_reference ()
355 return mono_exception_from_name (mono_get_corlib (), "System",
356 "NullReferenceException");
360 * mono_get_exception_execution_engine:
361 * @msg: the message to pass to the user
363 * Returns: a new instance of the `System.ExecutionEngineException`
366 mono_get_exception_execution_engine (const char *msg
)
368 return mono_exception_from_name_msg (mono_get_corlib (), "System", "ExecutionEngineException", msg
);
372 * mono_get_exception_serialization:
373 * @msg: the message to pass to the user
375 * Returns: a new instance of the `System.Runtime.Serialization.SerializationException`
378 mono_get_exception_serialization (const char *msg
)
380 return mono_exception_from_name_msg (mono_get_corlib (), "System.Runtime.Serialization", "SerializationException", msg
);
384 * mono_get_exception_invalid_cast:
386 * Returns: a new instance of the `System.InvalidCastException`
389 mono_get_exception_invalid_cast ()
391 return mono_exception_from_name (mono_get_corlib (), "System", "InvalidCastException");
395 * mono_get_exception_invalid_operation:
396 * @msg: the message to pass to the user
398 * Returns: a new instance of the `System.InvalidOperationException`
401 mono_get_exception_invalid_operation (const char *msg
)
403 return mono_exception_from_name_msg (mono_get_corlib (), "System",
404 "InvalidOperationException", msg
);
408 * mono_get_exception_index_out_of_range:
410 * Returns: a new instance of the `System.IndexOutOfRangeException`
413 mono_get_exception_index_out_of_range ()
415 return mono_exception_from_name (mono_get_corlib (), "System",
416 "IndexOutOfRangeException");
420 * mono_get_exception_array_type_mismatch:
422 * Returns: a new instance of the `System.ArrayTypeMismatchException`
425 mono_get_exception_array_type_mismatch ()
427 return mono_exception_from_name (mono_get_corlib (), "System",
428 "ArrayTypeMismatchException");
432 * mono_get_exception_type_load:
433 * @class_name: the name of the class that could not be loaded
434 * @assembly_name: the assembly where the class was looked up.
436 * Returns: a new instance of the `System.TypeLoadException`
439 mono_get_exception_type_load (MonoString
*class_name
, char *assembly_name
)
441 MonoString
*s
= assembly_name
? mono_string_new (mono_domain_get (), assembly_name
) : mono_string_new (mono_domain_get (), "");
444 MonoException
*ret
= mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System",
445 "TypeLoadException", class_name
, s
, &error
);
446 mono_error_assert_ok (&error
);
451 * mono_get_exception_not_implemented:
452 * @msg: the message to pass to the user
454 * Returns: a new instance of the `System.NotImplementedException`
457 mono_get_exception_not_implemented (const char *msg
)
459 return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotImplementedException", msg
);
463 * mono_get_exception_not_supported:
464 * @msg: the message to pass to the user
466 * Returns: a new instance of the `System.NotSupportedException`
469 mono_get_exception_not_supported (const char *msg
)
471 return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotSupportedException", msg
);
475 * mono_get_exception_missing_method:
476 * @class_name: the class where the lookup was performed.
477 * @member_name: the name of the missing method.
479 * Returns: a new instance of the `System.MissingMethodException`
482 mono_get_exception_missing_method (const char *class_name
, const char *member_name
)
484 MonoString
*s1
= mono_string_new (mono_domain_get (), class_name
);
485 MonoString
*s2
= mono_string_new (mono_domain_get (), member_name
);
488 MonoException
*ret
= mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System",
489 "MissingMethodException", s1
, s2
, &error
);
490 mono_error_assert_ok (&error
);
495 * mono_get_exception_missing_field:
496 * @class_name: the class where the lookup was performed
497 * @member_name: the name of the missing method.
499 * Returns: a new instance of the `System.MissingFieldException`
502 mono_get_exception_missing_field (const char *class_name
, const char *member_name
)
504 MonoString
*s1
= mono_string_new (mono_domain_get (), class_name
);
505 MonoString
*s2
= mono_string_new (mono_domain_get (), member_name
);
508 MonoException
*ret
= mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System",
509 "MissingFieldException", s1
, s2
, &error
);
510 mono_error_assert_ok (&error
);
515 * mono_get_exception_argument_null:
516 * @arg: the name of the argument that is null
518 * Returns: a new instance of the `System.ArgumentNullException`
521 mono_get_exception_argument_null (const char *arg
)
525 ex
= mono_exception_from_name (
526 mono_get_corlib (), "System", "ArgumentNullException");
529 MonoArgumentException
*argex
= (MonoArgumentException
*)ex
;
530 MONO_OBJECT_SETREF (argex
, param_name
, mono_string_new (mono_object_get_domain ((MonoObject
*)ex
), arg
));
537 * mono_get_exception_argument:
538 * @arg: the name of the invalid argument.
540 * Returns: a new instance of the `System.ArgumentException`
543 mono_get_exception_argument (const char *arg
, const char *msg
)
547 ex
= mono_exception_from_name_msg (
548 mono_get_corlib (), "System", "ArgumentException", msg
);
551 MonoArgumentException
*argex
= (MonoArgumentException
*)ex
;
552 MONO_OBJECT_SETREF (argex
, param_name
, mono_string_new (mono_object_get_domain ((MonoObject
*)ex
), arg
));
559 * mono_get_exception_argument_out_of_range:
560 * @arg: the name of the out of range argument.
562 * Returns: a new instance of the `System.ArgumentOutOfRangeException`
565 mono_get_exception_argument_out_of_range (const char *arg
)
569 ex
= mono_exception_from_name (
570 mono_get_corlib (), "System", "ArgumentOutOfRangeException");
573 MonoArgumentException
*argex
= (MonoArgumentException
*)ex
;
574 MONO_OBJECT_SETREF (argex
, param_name
, mono_string_new (mono_object_get_domain ((MonoObject
*)ex
), arg
));
581 * mono_get_exception_thread_state:
582 * @msg: the message to present to the user
584 * Returns: a new instance of the `System.Threading.ThreadStateException`
587 mono_get_exception_thread_state (const char *msg
)
589 return mono_exception_from_name_msg (
590 mono_get_corlib (), "System.Threading", "ThreadStateException", msg
);
594 * mono_get_exception_io:
595 * @msg: the message to present to the user
597 * Returns: a new instance of the `System.IO.IOException`
600 mono_get_exception_io (const char *msg
)
602 return mono_exception_from_name_msg (
603 mono_get_corlib (), "System.IO", "IOException", msg
);
607 * mono_get_exception_file_not_found:
608 * @fname: the name of the file not found.
610 * Returns: a new instance of the `System.IO.FileNotFoundException`
613 mono_get_exception_file_not_found (MonoString
*fname
)
616 MonoException
*ret
= mono_exception_from_name_two_strings_checked (
617 mono_get_corlib (), "System.IO", "FileNotFoundException", fname
, fname
, &error
);
618 mono_error_assert_ok (&error
);
623 * mono_get_exception_file_not_found2:
624 * @msg: an informative message for the user.
625 * @fname: the name of the file not found.
627 * Returns: a new instance of the `System.IO.FileNotFoundException`
630 mono_get_exception_file_not_found2 (const char *msg
, MonoString
*fname
)
632 MonoString
*s
= msg
? mono_string_new (mono_domain_get (), msg
) : NULL
;
635 MonoException
*ret
= mono_exception_from_name_two_strings_checked (
636 mono_get_corlib (), "System.IO", "FileNotFoundException", s
, fname
, &error
);
637 mono_error_assert_ok (&error
);
642 * mono_get_exception_type_initialization:
643 * @type_name: the name of the type that failed to initialize.
644 * @inner: the inner exception.
646 * Returns: a new instance of the `System.TypeInitializationException`
649 mono_get_exception_type_initialization (const gchar
*type_name
, MonoException
*inner
)
652 MonoException
*ret
= mono_get_exception_type_initialization_checked (type_name
, inner
, &error
);
653 if (!is_ok (&error
)) {
654 mono_error_cleanup (&error
);
662 mono_get_exception_type_initialization_checked (const gchar
*type_name
, MonoException
*inner
, MonoError
*error
)
670 klass
= mono_class_load_from_name (mono_get_corlib (), "System", "TypeInitializationException");
672 mono_class_init (klass
);
675 while ((method
= mono_class_get_methods (klass
, &iter
))) {
676 if (!strcmp (".ctor", mono_method_get_name (method
))) {
677 MonoMethodSignature
*sig
= mono_method_signature (method
);
679 if (sig
->param_count
== 2 && sig
->params
[0]->type
== MONO_TYPE_STRING
&& mono_class_from_mono_type (sig
->params
[1]) == mono_defaults
.exception_class
)
686 args
[0] = mono_string_new (mono_domain_get (), type_name
);
689 exc
= mono_object_new_checked (mono_domain_get (), klass
, error
);
690 mono_error_assert_ok (error
);
692 mono_runtime_invoke_checked (method
, exc
, args
, error
);
693 return_val_if_nok (error
, NULL
);
695 return (MonoException
*) exc
;
699 * mono_get_exception_synchronization_lock:
700 * @inner: the inner exception.
702 * Returns: a new instance of the `System.SynchronizationLockException`
705 mono_get_exception_synchronization_lock (const char *msg
)
707 return mono_exception_from_name_msg (mono_get_corlib (), "System.Threading", "SynchronizationLockException", msg
);
711 * mono_get_exception_cannot_unload_appdomain:
712 * @inner: the inner exception.
714 * Returns: a new instance of the `System.CannotUnloadAppDomainException`
717 mono_get_exception_cannot_unload_appdomain (const char *msg
)
719 return mono_exception_from_name_msg (mono_get_corlib (), "System", "CannotUnloadAppDomainException", msg
);
723 * mono_get_exception_appdomain_unloaded
725 * Returns: a new instance of the `System.AppDomainUnloadedException`
728 mono_get_exception_appdomain_unloaded (void)
730 return mono_exception_from_name (mono_get_corlib (), "System", "AppDomainUnloadedException");
734 * mono_get_exception_bad_image_format:
735 * @msg: an informative message for the user.
737 * Returns: a new instance of the `System.BadImageFormatException`
740 mono_get_exception_bad_image_format (const char *msg
)
742 return mono_exception_from_name_msg (mono_get_corlib (), "System", "BadImageFormatException", msg
);
746 * mono_get_exception_bad_image_format2:
747 * @msg: an informative message for the user.
748 * @fname: The full name of the file with the invalid image.
750 * Returns: a new instance of the `System.BadImageFormatException`
753 mono_get_exception_bad_image_format2 (const char *msg
, MonoString
*fname
)
755 MonoString
*s
= msg
? mono_string_new (mono_domain_get (), msg
) : NULL
;
758 MonoException
*ret
= mono_exception_from_name_two_strings_checked (
759 mono_get_corlib (), "System", "BadImageFormatException", s
, fname
, &error
);
760 mono_error_assert_ok (&error
);
765 * mono_get_exception_stack_overflow:
767 * Returns: a new instance of the `System.StackOverflowException`
770 mono_get_exception_stack_overflow (void)
772 return mono_exception_from_name (mono_get_corlib (), "System", "StackOverflowException");
776 * mono_get_exception_out_of_memory:
778 * Returns: a new instance of the `System.OutOfMemoryException`
781 mono_get_exception_out_of_memory (void)
783 return mono_exception_from_name (mono_get_corlib (), "System", "OutOfMemoryException");
787 * mono_get_exception_field_access:
789 * Returns: a new instance of the `System.FieldAccessException`
792 mono_get_exception_field_access (void)
794 return mono_exception_from_name (mono_get_corlib (), "System", "FieldAccessException");
798 * mono_get_exception_field_access2:
799 * @msg: an informative message for the user.
801 * Returns: a new instance of the `System.FieldAccessException`
804 mono_get_exception_field_access_msg (const char *msg
)
806 return mono_exception_from_name_msg (mono_get_corlib (), "System", "FieldAccessException", msg
);
810 * mono_get_exception_method_access:
812 * Returns: a new instance of the `System.MethodAccessException`
815 mono_get_exception_method_access (void)
817 return mono_exception_from_name (mono_get_corlib (), "System", "MethodAccessException");
821 * mono_get_exception_method_access2:
822 * @msg: an informative message for the user.
824 * Returns: a new instance of the `System.MethodAccessException`
827 mono_get_exception_method_access_msg (const char *msg
)
829 return mono_exception_from_name_msg (mono_get_corlib (), "System", "MethodAccessException", msg
);
833 * mono_get_exception_reflection_type_load:
834 * @types: an array of types that were defined in the moduled loaded.
835 * @exceptions: an array of exceptions that were thrown during the type loading.
837 * Returns: a new instance of the `System.Reflection.ReflectionTypeLoadException`
840 mono_get_exception_reflection_type_load (MonoArray
*types
, MonoArray
*exceptions
)
843 MonoException
*ret
= mono_get_exception_reflection_type_load_checked (types
, exceptions
, &error
);
844 if (is_ok (&error
)) {
845 mono_error_cleanup (&error
);
853 mono_get_exception_reflection_type_load_checked (MonoArray
*types
, MonoArray
*exceptions
, MonoError
*error
)
861 klass
= mono_class_load_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");
863 mono_class_init (klass
);
865 /* Find the Type[], Exception[] ctor */
867 while ((method
= mono_class_get_methods (klass
, &iter
))) {
868 if (!strcmp (".ctor", mono_method_get_name (method
))) {
869 MonoMethodSignature
*sig
= mono_method_signature (method
);
871 if (sig
->param_count
== 2 && sig
->params
[0]->type
== MONO_TYPE_SZARRAY
&& sig
->params
[1]->type
== MONO_TYPE_SZARRAY
)
879 args
[1] = exceptions
;
881 exc
= mono_object_new_checked (mono_domain_get (), klass
, error
);
882 mono_error_assert_ok (error
);
884 mono_runtime_invoke_checked (method
, exc
, args
, error
);
885 return_val_if_nok (error
, NULL
);
887 return (MonoException
*) exc
;
891 mono_get_exception_runtime_wrapped (MonoObject
*wrapped_exception
)
894 MonoException
*ret
= mono_get_exception_runtime_wrapped_checked (wrapped_exception
, &error
);
895 if (!is_ok (&error
)) {
896 mono_error_cleanup (&error
);
904 mono_get_exception_runtime_wrapped_checked (MonoObject
*wrapped_exception
, MonoError
*error
)
909 MonoDomain
*domain
= mono_domain_get ();
910 gpointer params
[16];
912 klass
= mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException");
914 o
= mono_object_new_checked (domain
, klass
, error
);
915 mono_error_assert_ok (error
);
916 g_assert (o
!= NULL
);
918 method
= mono_class_get_method_from_name (klass
, ".ctor", 1);
921 params
[0] = wrapped_exception
;
923 mono_runtime_invoke_checked (method
, o
, params
, error
);
924 return_val_if_nok (error
, NULL
);
926 return (MonoException
*)o
;
930 append_frame_and_continue (MonoMethod
*method
, gpointer ip
, size_t native_offset
, gboolean managed
, gpointer user_data
)
932 MonoDomain
*domain
= mono_domain_get ();
933 GString
*text
= (GString
*)user_data
;
936 char *msg
= mono_debug_print_stack_frame (method
, native_offset
, domain
);
937 g_string_append_printf (text
, "%s\n", msg
);
940 g_string_append_printf (text
, "<unknown native frame 0x%x>\n", ip
);
947 mono_exception_get_managed_backtrace (MonoException
*exc
)
951 text
= g_string_new_len (NULL
, 20);
953 if (!mono_get_eh_callbacks ()->mono_exception_walk_trace (exc
, append_frame_and_continue
, text
))
954 g_string_append (text
, "managed backtrace not available\n");
956 return g_string_free (text
, FALSE
);
960 mono_exception_get_native_backtrace (MonoException
*exc
)
962 #ifdef HAVE_BACKTRACE_SYMBOLS
964 MonoArray
*arr
= exc
->native_trace_ips
;
970 return g_strdup ("");
971 domain
= mono_domain_get ();
972 len
= mono_array_length (arr
);
973 text
= g_string_new_len (NULL
, len
* 20);
974 messages
= backtrace_symbols (mono_array_addr (arr
, gpointer
, 0), len
);
977 for (i
= 0; i
< len
; ++i
) {
978 gpointer ip
= mono_array_get (arr
, gpointer
, i
);
979 MonoJitInfo
*ji
= mono_jit_info_table_find (mono_domain_get (), (char *)ip
);
981 char *msg
= mono_debug_print_stack_frame (mono_jit_info_get_method (ji
), (char*)ip
- (char*)ji
->code_start
, domain
);
982 g_string_append_printf (text
, "%s\n", msg
);
985 g_string_append_printf (text
, "%s\n", messages
[i
]);
990 return g_string_free (text
, FALSE
);
992 return g_strdup ("");
997 ves_icall_Mono_Runtime_GetNativeStackTrace (MonoException
*exc
)
1002 mono_set_pending_exception (mono_get_exception_argument_null ("exception"));
1006 trace
= mono_exception_get_native_backtrace (exc
);
1007 res
= mono_string_new (mono_domain_get (), trace
);
1013 * mono_error_raise_exception:
1014 * @target_error: the exception to raise
1016 * Raises the exception of @target_error.
1017 * Does nothing if @target_error has a success error code.
1018 * Aborts in case of a double fault. This happens when it can't recover from an error caused by trying
1019 * to construct the first exception object.
1020 * The error object @target_error is cleaned up.
1023 mono_error_raise_exception (MonoError
*target_error
)
1025 MonoException
*ex
= mono_error_convert_to_exception (target_error
);
1027 mono_raise_exception (ex
);
1031 * mono_error_set_pending_exception:
1035 * If @error is set, convert it to an exception and set the pending exception for the current icall.
1036 * Returns TRUE if @error was set, or FALSE otherwise, so that you can write:
1037 * if (mono_error_set_pending_exception (error)) {
1038 * { ... cleanup code ... }
1043 mono_error_set_pending_exception (MonoError
*error
)
1045 MonoException
*ex
= mono_error_convert_to_exception (error
);
1047 mono_set_pending_exception (ex
);