/** * mono_get_exception_execution_engine: * \param msg the message to pass to the user * \returns a new instance of the \c System.ExecutionEngineException */ MonoException * mono_get_exception_execution_engine (const char *msg) { MonoException *result; MONO_ENTER_GC_UNSAFE; result = mono_exception_from_name_msg (mono_get_corlib (), "System", "ExecutionEngineException", msg); MONO_EXIT_GC_UNSAFE; return result; }
/** * mono_get_exception_argument: * @arg: the name of the invalid argument. * * Returns: a new instance of the `System.ArgumentException` */ MonoException * mono_get_exception_argument (const char *arg, const char *msg) { MonoException *ex; ex = mono_exception_from_name_msg ( mono_get_corlib (), "System", "ArgumentException", msg); if (arg) { MonoArgumentException *argex = (MonoArgumentException *)ex; MONO_OBJECT_SETREF (argex, param_name, mono_string_new (mono_object_get_domain ((MonoObject*)ex), arg)); } return ex; }
/** * mono_get_exception_method_access2: * @msg: an informative message for the user. * * Returns: a new instance of the `System.MethodAccessException` */ MonoException * mono_get_exception_method_access_msg (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "MethodAccessException", msg); }
/** * mono_get_exception_bad_image_format: * @msg: an informative message for the user. * * Returns: a new instance of the `System.BadImageFormatException` */ MonoException * mono_get_exception_bad_image_format (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "BadImageFormatException", msg); }
/** * mono_get_exception_cannot_unload_appdomain: * @inner: the inner exception. * * Returns: a new instance of the `System.CannotUnloadAppDomainException` */ MonoException * mono_get_exception_cannot_unload_appdomain (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "CannotUnloadAppDomainException", msg); }
/** * mono_get_exception_synchronization_lock: * @inner: the inner exception. * * Returns: a new instance of the `System.SynchronizationLockException` */ MonoException * mono_get_exception_synchronization_lock (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System.Threading", "SynchronizationLockException", msg); }
/** * mono_get_exception_io: * @msg: the message to present to the user * * Returns: a new instance of the `System.IO.IOException` */ MonoException * mono_get_exception_io (const char *msg) { return mono_exception_from_name_msg ( mono_get_corlib (), "System.IO", "IOException", msg); }
/** * mono_get_exception_thread_state: * @msg: the message to present to the user * * Returns: a new instance of the `System.Threading.ThreadStateException` */ MonoException * mono_get_exception_thread_state (const char *msg) { return mono_exception_from_name_msg ( mono_get_corlib (), "System.Threading", "ThreadStateException", msg); }
/** * mono_get_exception_not_supported: * @msg: the message to pass to the user * * Returns: a new instance of the `System.NotSupportedException` */ MonoException * mono_get_exception_not_supported (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "NotSupportedException", msg); }
/** * mono_get_exception_invalid_operation: * @msg: the message to pass to the user * * Returns: a new instance of the `System.InvalidOperationException` */ MonoException * mono_get_exception_invalid_operation (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "InvalidOperationException", msg); }
/** * mono_get_exception_serialization: * @msg: the message to pass to the user * * Returns: a new instance of the `System.Runtime.Serialization.SerializationException` */ MonoException * mono_get_exception_serialization (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System.Runtime.Serialization", "SerializationException", msg); }
/** * mono_get_exception_execution_engine: * @msg: the message to pass to the user * * Returns: a new instance of the `System.ExecutionEngineException` */ MonoException * mono_get_exception_execution_engine (const char *msg) { return mono_exception_from_name_msg (mono_get_corlib (), "System", "ExecutionEngineException", msg); }
/*Can fail with out-of-memory*/ MonoException* mono_error_prepare_exception (MonoError *oerror, MonoError *error_out) { MonoErrorInternal *error = (MonoErrorInternal*)oerror; MonoException* exception = NULL; MonoString *assembly_name = NULL, *type_name = NULL, *method_name = NULL, *field_name = NULL, *msg = NULL; MonoDomain *domain = mono_domain_get (); mono_error_init (error_out); switch (error->error_code) { case MONO_ERROR_NONE: return NULL; case MONO_ERROR_MISSING_METHOD: if ((error->type_name || error->exn.klass) && error->member_name) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; method_name = mono_string_new (domain, error->member_name); if (!method_name) { mono_error_set_out_of_memory (error_out, "Could not allocate method name"); break; } exception = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "MissingMethodException", type_name, method_name, error_out); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MissingMethodException", error->full_message); } break; case MONO_ERROR_MISSING_FIELD: if ((error->type_name || error->exn.klass) && error->member_name) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; field_name = mono_string_new (domain, error->member_name); if (!field_name) { mono_error_set_out_of_memory (error_out, "Could not allocate field name"); break; } exception = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "MissingFieldException", type_name, field_name, error_out); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MissingFieldException", error->full_message); } break; case MONO_ERROR_TYPE_LOAD: 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 = mono_string_new (domain, error->assembly_name); if (!assembly_name) { mono_error_set_out_of_memory (error_out, "Could not allocate assembly name"); break; } } exception = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System", "TypeLoadException", type_name, assembly_name, error_out); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "TypeLoadException", error->full_message); } break; case MONO_ERROR_FILE_NOT_FOUND: case MONO_ERROR_BAD_IMAGE: if (error->assembly_name) { msg = mono_string_new (domain, error->full_message); if (!msg) { mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } if (error->assembly_name) { assembly_name = mono_string_new (domain, error->assembly_name); if (!assembly_name) { mono_error_set_out_of_memory (error_out, "Could not allocate assembly name"); break; } } if (error->error_code == MONO_ERROR_FILE_NOT_FOUND) exception = mono_exception_from_name_two_strings_checked (mono_get_corlib (), "System.IO", "FileNotFoundException", msg, assembly_name, error_out); else exception = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "BadImageFormatException", msg, assembly_name, error_out); } else { if (error->error_code == MONO_ERROR_FILE_NOT_FOUND) exception = mono_exception_from_name_msg (mono_get_corlib (), "System.IO", "FileNotFoundException", error->full_message); else exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "BadImageFormatException", error->full_message); } break; case MONO_ERROR_OUT_OF_MEMORY: exception = mono_get_exception_out_of_memory (); break; case MONO_ERROR_ARGUMENT: exception = mono_get_exception_argument (error->first_argument, error->full_message); break; case MONO_ERROR_ARGUMENT_NULL: exception = mono_get_exception_argument_null (error->first_argument); break; case MONO_ERROR_NOT_VERIFIABLE: { char *type_name = NULL, *message; if (error->exn.klass) { type_name = mono_type_get_full_name (error->exn.klass); if (!type_name) { mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } } message = g_strdup_printf ("Error in %s:%s %s", type_name, error->member_name, error->full_message); if (!message) { g_free (type_name); mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } exception = mono_exception_from_name_msg (mono_defaults.corlib, "System.Security", "VerificationException", message); g_free (message); g_free (type_name); 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_from_name_msg (mono_defaults.corlib, error->exception_name_space, error->exception_name, error->full_message); break; case MONO_ERROR_EXCEPTION_INSTANCE: exception = (MonoException*) mono_gchandle_get_target (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: { gboolean lacks_message = error->flags & MONO_ERROR_INCOMPLETE; if (lacks_message) return mono_exception_from_name_msg (mono_defaults.corlib, "System", "InvalidProgramException", ""); else return mono_exception_from_name_msg (mono_defaults.corlib, "System", "InvalidProgramException", error->full_message); } default: mono_error_set_execution_engine (error_out, "Invalid error-code %d", error->error_code); } if (!mono_error_ok (error_out)) return NULL; if (!exception) mono_error_set_out_of_memory (error_out, "Could not allocate exception object"); return exception; }
/*Can fail with out-of-memory*/ MonoException* mono_error_prepare_exception (MonoError *oerror, MonoError *error_out) { MonoErrorInternal *error = (MonoErrorInternal*)oerror; MonoException* exception = NULL; MonoString *assembly_name = NULL, *type_name = NULL, *method_name = NULL, *field_name = NULL, *msg = NULL; MonoDomain *domain = mono_domain_get (); mono_error_init (error_out); switch (error->error_code) { case MONO_ERROR_NONE: return NULL; case MONO_ERROR_MISSING_METHOD: if ((error->type_name || error->klass) && error->member_name) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; method_name = mono_string_new (domain, error->member_name); if (!method_name) { mono_error_set_out_of_memory (error_out, "Could not allocate method name"); break; } exception = mono_exception_from_name_two_strings (mono_defaults.corlib, "System", "MissingMethodException", type_name, method_name); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MissingMethodException", mono_internal_error_get_message (error)); } break; case MONO_ERROR_MISSING_FIELD: if ((error->type_name || error->klass) && error->member_name) { type_name = get_type_name_as_mono_string (error, domain, error_out); if (!mono_error_ok (error_out)) break; field_name = mono_string_new (domain, error->member_name); if (!field_name) { mono_error_set_out_of_memory (error_out, "Could not allocate field name"); break; } exception = mono_exception_from_name_two_strings (mono_defaults.corlib, "System", "MissingFieldException", type_name, field_name); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "MissingFieldException", mono_internal_error_get_message (error)); } break; case MONO_ERROR_TYPE_LOAD: if (error->type_name || error->assembly_name) { 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 = mono_string_new (domain, error->assembly_name); if (!assembly_name) { mono_error_set_out_of_memory (error_out, "Could not allocate assembly name"); break; } } exception = mono_exception_from_name_two_strings (mono_get_corlib (), "System", "TypeLoadException", type_name, assembly_name); if (exception) set_message_on_exception (exception, error, error_out); } else { exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "TypeLoadException", mono_internal_error_get_message (error)); } break; case MONO_ERROR_FILE_NOT_FOUND: case MONO_ERROR_BAD_IMAGE: if (error->assembly_name) { msg = mono_string_new (domain, mono_internal_error_get_message (error)); if (!msg) { mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } if (error->assembly_name) { assembly_name = mono_string_new (domain, error->assembly_name); if (!assembly_name) { mono_error_set_out_of_memory (error_out, "Could not allocate assembly name"); break; } } if (error->error_code == MONO_ERROR_FILE_NOT_FOUND) exception = mono_exception_from_name_two_strings (mono_get_corlib (), "System.IO", "FileNotFoundException", msg, assembly_name); else exception = mono_exception_from_name_two_strings (mono_defaults.corlib, "System", "BadImageFormatException", msg, assembly_name); } else { if (error->error_code == MONO_ERROR_FILE_NOT_FOUND) exception = mono_exception_from_name_msg (mono_get_corlib (), "System.IO", "FileNotFoundException", mono_internal_error_get_message (error)); else exception = mono_exception_from_name_msg (mono_defaults.corlib, "System", "BadImageFormatException", mono_internal_error_get_message (error)); } break; case MONO_ERROR_OUT_OF_MEMORY: exception = mono_get_exception_out_of_memory (); break; case MONO_ERROR_ARGUMENT: exception = mono_get_exception_argument (error->type_name, mono_internal_error_get_message (error)); break; case MONO_ERROR_NOT_VERIFIABLE: { char *type_name = NULL, *message; if (error->klass) { type_name = mono_type_get_full_name (error->klass); if (!type_name) { mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } } message = g_strdup_printf ("Error in %s:%s %s", type_name, error->member_name, mono_internal_error_get_message (error)); if (!message) { g_free (type_name); mono_error_set_out_of_memory (error_out, "Could not allocate message"); break; } exception = mono_exception_from_name_msg (mono_defaults.corlib, "System.Security", "VerificationException", message); g_free (message); g_free (type_name); break; } case MONO_ERROR_GENERIC: if (!error->exception_name_space || !error->exception_name) mono_error_set_generic_error (error_out, "System", "ExecutionEngineException", "MonoError with generic error but no exception name was supplied"); else exception = mono_exception_from_name_msg (mono_defaults.corlib, error->exception_name_space, error->exception_name, mono_internal_error_get_message (error)); break; default: mono_error_set_generic_error (error_out, "System", "ExecutionEngineException", "Invalid error-code %d", error->error_code); } if (!mono_error_ok (error_out)) return NULL; if (!exception) mono_error_set_out_of_memory (error_out, "Could not allocate exception object"); return exception; }