MonoExceptionHandle mono_get_exception_runtime_wrapped_handle (MonoObjectHandle wrapped_exception, MonoError *error) { HANDLE_FUNCTION_ENTER (); MonoClass *klass; MonoMethod *method; klass = mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException"); MonoObjectHandle o = mono_object_new_handle (mono_domain_get (), klass, error); mono_error_assert_ok (error); g_assert (!MONO_HANDLE_IS_NULL (o)); method = mono_class_get_method_from_name_checked (klass, ".ctor", 1, 0, error); mono_error_assert_ok (error); g_assert (method); gpointer args [ ] = { MONO_HANDLE_RAW (wrapped_exception) }; mono_runtime_invoke_handle (method, o, args, error); goto_if_nok (error, return_null); goto exit; return_null: o = mono_new_null (); exit: HANDLE_FUNCTION_RETURN_REF (MonoException, MONO_HANDLE_CAST (MonoException, o)); }
/** * mono_get_exception_reflection_type_load: * \param types an array of types that were defined in the moduled loaded. * \param exceptions an array of exceptions that were thrown during the type loading. * \returns a new instance of the \c System.Reflection.ReflectionTypeLoadException */ MonoException * mono_get_exception_reflection_type_load (MonoArray *types_raw, MonoArray *exceptions_raw) { HANDLE_FUNCTION_ENTER (); ERROR_DECL (error); MONO_HANDLE_DCL (MonoArray, types); MONO_HANDLE_DCL (MonoArray, exceptions); MonoExceptionHandle ret = mono_get_exception_reflection_type_load_checked (types, exceptions, error); if (!is_ok (error)) ret = MONO_HANDLE_CAST (MonoException, mono_new_null ()); mono_error_cleanup (error); HANDLE_FUNCTION_RETURN_OBJ (ret); }
/** * mono_get_exception_type_initialization: * \param type_name the name of the type that failed to initialize. * \param inner the inner exception. * \returns a new instance of the \c System.TypeInitializationException */ MonoException * mono_get_exception_type_initialization (const gchar *type_name, MonoException* inner_raw) { HANDLE_FUNCTION_ENTER (); MONO_HANDLE_DCL (MonoException, inner); ERROR_DECL (error); MonoExceptionHandle ret = mono_get_exception_type_initialization_handle (type_name, inner, error); if (!is_ok (error)) { ret = MONO_HANDLE_CAST (MonoException, mono_new_null ()); mono_error_cleanup (error); } HANDLE_FUNCTION_RETURN_OBJ (ret); }
/** * mono_get_exception_runtime_wrapped: */ MonoException * mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception_raw) { HANDLE_FUNCTION_ENTER (); ERROR_DECL (error); MONO_HANDLE_DCL (MonoObject, wrapped_exception); MonoExceptionHandle ret = mono_get_exception_runtime_wrapped_handle (wrapped_exception, error); if (!is_ok (error)) { mono_error_cleanup (error); ret = MONO_HANDLE_CAST (MonoException, mono_new_null ()); } HANDLE_FUNCTION_RETURN_OBJ (ret); }
MonoExceptionHandle mono_get_exception_type_initialization_handle (const gchar *type_name, MonoExceptionHandle inner, MonoError *error) { HANDLE_FUNCTION_ENTER (); MonoClass *klass; MonoMethod *method; gpointer iter; error_init (error); klass = mono_class_load_from_name (mono_get_corlib (), "System", "TypeInitializationException"); mono_class_init_internal (klass); iter = NULL; while ((method = mono_class_get_methods (klass, &iter))) { if (!strcmp (".ctor", mono_method_get_name (method))) { MonoMethodSignature *sig = mono_method_signature_internal (method); if (sig->param_count == 2 && sig->params [0]->type == MONO_TYPE_STRING && mono_class_from_mono_type_internal (sig->params [1]) == mono_defaults.exception_class) break; } method = NULL; } g_assert (method); MonoDomain * const domain = mono_domain_get (); MonoStringHandle type_name_str = mono_string_new_handle (domain, type_name, error); mono_error_assert_ok (error); gpointer args [ ] = { MONO_HANDLE_RAW (type_name_str), MONO_HANDLE_RAW (inner) }; MonoObjectHandle exc = mono_object_new_handle (domain, klass, error); mono_error_assert_ok (error); mono_runtime_invoke_handle (method, exc, args, error); goto_if_nok (error, return_null); goto exit; return_null: exc = mono_new_null (); exit: HANDLE_FUNCTION_RETURN_REF (MonoException, MONO_HANDLE_CAST (MonoException, exc)); }
MonoExceptionHandle mono_get_exception_reflection_type_load_checked (MonoArrayHandle types, MonoArrayHandle exceptions, MonoError *error) { HANDLE_FUNCTION_ENTER (); MonoClass *klass; MonoMethod *method; gpointer iter; error_init (error); klass = mono_class_load_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException"); mono_class_init_internal (klass); /* Find the Type[], Exception[] ctor */ iter = NULL; while ((method = mono_class_get_methods (klass, &iter))) { if (!strcmp (".ctor", mono_method_get_name (method))) { MonoMethodSignature *sig = mono_method_signature_internal (method); if (sig->param_count == 2 && sig->params [0]->type == MONO_TYPE_SZARRAY && sig->params [1]->type == MONO_TYPE_SZARRAY) break; } method = NULL; } g_assert (method); MonoExceptionHandle exc = MONO_HANDLE_CAST (MonoException, MONO_HANDLE_NEW (MonoObject, mono_object_new_checked (mono_domain_get (), klass, error))); mono_error_assert_ok (error); gpointer args [ ] = { MONO_HANDLE_RAW (types), MONO_HANDLE_RAW (exceptions) }; mono_runtime_invoke_checked (method, MONO_HANDLE_RAW (exc), args, error); goto_if_nok (error, return_null); goto exit; return_null: exc = MONO_HANDLE_CAST (MonoException, mono_new_null ()); exit: HANDLE_FUNCTION_RETURN_REF (MonoException, exc); }
static MonoExceptionHandle create_exception_two_strings (MonoClass *klass, MonoStringHandle a1, MonoStringHandle a2, MonoError *error) { HANDLE_FUNCTION_ENTER (); MonoMethod *method = NULL; int const count = 1 + !MONO_HANDLE_IS_NULL (a2); gpointer iter; MonoMethod *m; MonoObjectHandle o = mono_object_new_handle (mono_domain_get (), klass, error); mono_error_assert_ok (error); iter = NULL; while ((m = mono_class_get_methods (klass, &iter))) { MonoMethodSignature *sig; if (strcmp (".ctor", mono_method_get_name (m))) continue; sig = mono_method_signature_internal (m); if (sig->param_count != count) continue; if (sig->params [0]->type != MONO_TYPE_STRING) continue; if (count == 2 && sig->params [1]->type != MONO_TYPE_STRING) continue; method = m; break; } gpointer args [ ] = { MONO_HANDLE_RAW (a1), MONO_HANDLE_RAW (a2) }; mono_runtime_invoke_handle (method, o, args, error); if (!is_ok (error)) o = mono_new_null (); HANDLE_FUNCTION_RETURN_REF (MonoException, MONO_HANDLE_CAST (MonoException, o)); }
MonoExceptionHandle mono_corlib_exception_new_with_args (const char *name_space, const char *name, const char *arg_0, const char *arg_1, MonoError *error) { HANDLE_FUNCTION_ENTER (); MonoStringHandle str_0 = NULL_HANDLE_STRING; MonoStringHandle str_1 = NULL_HANDLE_STRING; MonoExceptionHandle ex = MONO_HANDLE_CAST (MonoException, NULL_HANDLE); MonoDomain * const domain = mono_domain_get (); str_0 = arg_0 ? mono_string_new_handle (domain, arg_0, error) : NULL_HANDLE_STRING; goto_if_nok (error, return_null); str_1 = arg_1 ? mono_string_new_handle (domain, arg_1, error) : NULL_HANDLE_STRING; goto_if_nok (error, return_null); ex = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, name_space, name, str_0, str_1, error); goto exit; return_null: ex = MONO_HANDLE_CAST (MonoException, mono_new_null ()); exit: HANDLE_FUNCTION_RETURN_REF (MonoException, ex); }
/*Can fail with out-of-memory*/ MonoException* mono_error_prepare_exception (MonoError *oerror, MonoError *error_out) { HANDLE_FUNCTION_ENTER (); MonoErrorInternal *error = (MonoErrorInternal*)oerror; MonoExceptionHandle exception = MONO_HANDLE_CAST (MonoException, mono_new_null ()); MonoDomain *domain = mono_domain_get (); char *type_name = NULL; char *message = NULL; error_init (error_out); const guint16 error_code = error->error_code; g_assert (error_code != MONO_ERROR_CLEANUP_CALLED_SENTINEL); switch (error_code) { case MONO_ERROR_NONE: goto exit; case MONO_ERROR_MISSING_METHOD: exception = mono_corlib_exception_new_with_args ("System", "MissingMethodException", error->full_message, error->first_argument, error_out); break; case MONO_ERROR_BAD_IMAGE: exception = mono_corlib_exception_new_with_args ("System", "BadImageFormatException", error->full_message, error->first_argument, error_out); break; case MONO_ERROR_FILE_NOT_FOUND: exception = mono_corlib_exception_new_with_args ("System.IO", "FileNotFoundException", error->full_message, error->first_argument, error_out); break; case MONO_ERROR_MISSING_FIELD: exception = mono_corlib_exception_new_with_args ("System", "MissingFieldException", error->full_message, error->first_argument, error_out); break; case MONO_ERROR_MEMBER_ACCESS: exception = mono_exception_new_by_name_msg (mono_defaults.corlib, "System", "MemberAccessException", error->full_message, error_out); break; case MONO_ERROR_TYPE_LOAD: { MonoStringHandle assembly_name; MonoStringHandle type_name; if ((error->type_name && error->assembly_name) || error->exn.klass) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; if (error->assembly_name) { assembly_name = string_new_cleanup (domain, error->assembly_name); if (MONO_HANDLE_IS_NULL (assembly_name)) { mono_error_set_out_of_memory (error_out, "Could not allocate assembly name"); break; } } else { assembly_name = mono_string_empty_handle (domain); } exception = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System", "TypeLoadException", type_name, assembly_name, error_out); if (!MONO_HANDLE_IS_NULL (exception)) { const char *full_message = error->full_message; if (full_message && full_message [0]) { MonoStringHandle msg = string_new_cleanup (mono_domain_get (), full_message); if (!MONO_HANDLE_IS_NULL (msg)) MONO_HANDLE_SET (exception, message, msg); else mono_error_set_out_of_memory (error_out, "Could not allocate exception object"); } } } else { exception = mono_exception_new_by_name_msg (mono_defaults.corlib, "System", "TypeLoadException", error->full_message, error_out); } } break; case MONO_ERROR_OUT_OF_MEMORY: if (domain) exception = MONO_HANDLE_NEW (MonoException, domain->out_of_memory_ex); if (MONO_HANDLE_IS_NULL (exception)) exception = mono_get_exception_out_of_memory_handle (); break; case MONO_ERROR_ARGUMENT: exception = mono_exception_new_argument (error->first_argument, error->full_message, error_out); break; case MONO_ERROR_ARGUMENT_NULL: exception = mono_exception_new_argument_null (error->first_argument, error_out); break; case MONO_ERROR_ARGUMENT_OUT_OF_RANGE: exception = mono_exception_new_argument_out_of_range(error->first_argument, error->full_message, error_out); break; case MONO_ERROR_NOT_VERIFIABLE: if (error->exn.klass) { type_name = mono_type_get_full_name (error->exn.klass); if (!type_name) goto out_of_memory; } message = g_strdup_printf ("Error in %s:%s %s", type_name, error->member_name, error->full_message); if (!message) goto out_of_memory; exception = mono_exception_new_by_name_msg (mono_defaults.corlib, "System.Security", "VerificationException", message, error_out); break; case MONO_ERROR_GENERIC: if (!error->exception_name_space || !error->exception_name) mono_error_set_execution_engine (error_out, "MonoError with generic error but no exception name was supplied"); else exception = mono_exception_new_by_name_msg (mono_defaults.corlib, error->exception_name_space, error->exception_name, error->full_message, error_out); break; case MONO_ERROR_EXCEPTION_INSTANCE: exception = MONO_HANDLE_CAST (MonoException, mono_gchandle_get_target_handle (error->exn.instance_handle)); break; case MONO_ERROR_CLEANUP_CALLED_SENTINEL: mono_error_set_execution_engine (error_out, "MonoError reused after mono_error_cleanup"); break; case MONO_ERROR_INVALID_PROGRAM: exception = mono_exception_new_by_name_msg (mono_defaults.corlib, "System", "InvalidProgramException", (error->flags & MONO_ERROR_INCOMPLETE) ? "" : error->full_message, error_out); break; default: mono_error_set_execution_engine (error_out, "Invalid error-code %d", error->error_code); } if (!mono_error_ok (error_out)) goto return_null; if (MONO_HANDLE_IS_NULL (exception)) mono_error_set_out_of_memory (error_out, "Could not allocate exception object"); goto exit; out_of_memory: mono_error_set_out_of_memory (error_out, "Could not allocate message"); goto exit; return_null: exception = MONO_HANDLE_CAST (MonoException, mono_new_null ()); exit: g_free (message); g_free (type_name); HANDLE_FUNCTION_RETURN_OBJ (exception); }