示例#1
0
MonoException *
mono_get_exception_runtime_wrapped_checked (MonoObject *wrapped_exception, MonoError *error)
{
	MonoClass *klass;
	MonoObject *o;
	MonoMethod *method;
	MonoDomain *domain = mono_domain_get ();
	gpointer params [16];

	klass = mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException");

	o = mono_object_new_checked (domain, klass, error);
	mono_error_assert_ok (error);
	g_assert (o != NULL);

	method = mono_class_get_method_from_name (klass, ".ctor", 1);
	g_assert (method);

	params [0] = wrapped_exception;

	mono_runtime_invoke_checked (method, o, params, error);
	return_val_if_nok (error, NULL);

	return (MonoException *)o;
}	
示例#2
0
MonoException *
mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;
	MonoMethod *method;
	MonoDomain *domain = mono_domain_get ();
	gpointer params [16];

	klass = mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException");

	o = mono_object_new_checked (domain, klass, &error);
	g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */

	method = mono_class_get_method_from_name (klass, ".ctor", 1);
	g_assert (method);

	params [0] = wrapped_exception;

	mono_runtime_invoke_checked (method, o, params, &error);
	mono_error_raise_exception (&error); /* FIXME don't raise here */

	return (MonoException *)o;
}	
示例#3
0
/**
 * mono_exception_from_token:
 * @image: the Mono image where to look for the class
 * @token: The type token of the class
 *
 * Creates an exception of the type given by @token.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_token (MonoImage *image, guint32 token)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;

	klass = mono_class_get_checked (image, token, &error);
	g_assert (mono_error_ok (&error)); /* FIXME handle the error. */

	o = mono_object_new_checked (mono_domain_get (), klass, &error);
	g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */
	
	mono_runtime_object_init (o);

	return (MonoException *)o;
}
示例#4
0
/**
 * mono_exception_from_token:
 * @image: the Mono image where to look for the class
 * @token: The type token of the class
 *
 * Creates an exception of the type given by @token.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_token (MonoImage *image, guint32 token)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;

	klass = mono_class_get_checked (image, token, &error);
	mono_error_assert_ok (&error);

	o = mono_object_new_checked (mono_domain_get (), klass, &error);
	mono_error_assert_ok (&error);
	
	mono_runtime_object_init_checked (o, &error);
	mono_error_assert_ok (&error);

	return (MonoException *)o;
}
示例#5
0
static MonoException *
create_exception_two_strings (MonoClass *klass, MonoString *a1, MonoString *a2)
{
	MonoError error;
	MonoDomain *domain = mono_domain_get ();
	MonoMethod *method = NULL;
	MonoObject *o;
	int count = 1;
	gpointer args [2];
	gpointer iter;
	MonoMethod *m;

	if (a2 != NULL)
		count++;
	
	o = mono_object_new_checked (domain, 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 (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;
	}

	args [0] = a1;
	args [1] = a2;

	mono_runtime_invoke_checked (method, o, args, &error);
	mono_error_raise_exception (&error); /* FIXME don't raise here */

	return (MonoException *) o;
}
示例#6
0
/**
 * mono_exception_from_name_domain:
 * @domain: Domain where the return object will be created.
 * @image: the Mono image where to look for the class
 * @name_space: the namespace for the class
 * @name: class name
 *
 * Creates an exception object of the given namespace/name class on
 * the given domain.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image, 
				 const char* name_space, const char *name)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;
	MonoDomain *caller_domain = mono_domain_get ();

	klass = mono_class_load_from_name (image, name_space, name);

	o = mono_object_new_checked (domain, klass, &error);
	g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */

	if (domain != caller_domain)
		mono_domain_set_internal (domain);
	mono_runtime_object_init (o);
	if (domain != caller_domain)
		mono_domain_set_internal (caller_domain);

	return (MonoException *)o;
}
示例#7
0
/**
 * mono_get_exception_reflection_type_load:
 * @types: an array of types that were defined in the moduled loaded.
 * @exceptions: an array of exceptions that were thrown during the type loading.
 *
 * Returns: a new instance of the `System.Reflection.ReflectionTypeLoadException`
 */
MonoException *
mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions)
{
	MonoError error;
	MonoClass *klass;
	gpointer args [2];
	MonoObject *exc;
	MonoMethod *method;
	gpointer iter;

	klass = mono_class_load_from_name (mono_get_corlib (), "System.Reflection", "ReflectionTypeLoadException");

	mono_class_init (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 (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);

	args [0] = types;
	args [1] = exceptions;

	exc = mono_object_new_checked (mono_domain_get (), klass, &error);
	mono_error_assert_ok (&error);

	mono_runtime_invoke_checked (method, exc, args, &error);
	mono_error_raise_exception (&error); /* FIXME don't raise here */

	return (MonoException *) exc;
}
示例#8
0
/**
 * mono_get_exception_type_initialization:
 * @type_name: the name of the type that failed to initialize.
 * @inner: the inner exception.
 *
 * Returns: a new instance of the `System.TypeInitializationException`
 */
MonoException *
mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner)
{
	MonoError error;
	MonoClass *klass;
	gpointer args [2];
	MonoObject *exc;
	MonoMethod *method;
	gpointer iter;

	klass = mono_class_load_from_name (mono_get_corlib (), "System", "TypeInitializationException");

	mono_class_init (klass);

	iter = NULL;
	while ((method = mono_class_get_methods (klass, &iter))) {
		if (!strcmp (".ctor", mono_method_get_name (method))) {
			MonoMethodSignature *sig = mono_method_signature (method);

			if (sig->param_count == 2 && sig->params [0]->type == MONO_TYPE_STRING && mono_class_from_mono_type (sig->params [1]) == mono_defaults.exception_class)
				break;
		}
		method = NULL;
	}
	g_assert (method);

	args [0] = mono_string_new (mono_domain_get (), type_name);
	args [1] = inner;

	exc = mono_object_new_checked (mono_domain_get (), klass, &error);
	mono_error_assert_ok (&error);
	mono_runtime_invoke_checked (method, exc, args, &error);
	mono_error_raise_exception (&error); /* FIXME don't raise here */

	return (MonoException *) exc;
}
示例#9
0
文件: exception.c 项目: vargaz/mono
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);
}
示例#10
0
MonoArray*
ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean neutral,
		MonoBoolean specific, MonoBoolean installed)
{
	MonoError error;
	MonoArray *ret;
	MonoClass *klass;
	MonoCultureInfo *culture;
	MonoDomain *domain;
	const CultureInfoEntry *ci;
	gint i, len;
	gboolean is_neutral;

	domain = mono_domain_get ();

	len = 0;
	for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
		ci = &culture_entries [i];
		is_neutral = ci->territory == 0;
		if ((neutral && is_neutral) || (specific && !is_neutral))
			len++;
	}

	klass = mono_class_get_culture_info_class ();

	/* The InvariantCulture is not in culture_entries */
	/* We reserve the first slot in the array for it */
	if (neutral)
		len++;

	ret = mono_array_new_checked (domain, klass, len, &error);
	if (!is_ok (&error))
		goto fail;

	if (len == 0)
		return ret;

	len = 0;
	if (neutral)
		mono_array_setref (ret, len++, NULL);

	for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
		ci = &culture_entries [i];
		is_neutral = ci->territory == 0;
		if ((neutral && is_neutral) || (specific && !is_neutral)) {
			culture = (MonoCultureInfo *) mono_object_new_checked (domain, klass, &error);
			if (!is_ok (&error)) goto fail;
			mono_runtime_object_init_checked ((MonoObject *) culture, &error);
			if (!is_ok (&error)) goto fail;
			if (!construct_culture (culture, ci, &error))
				goto fail;
			culture->use_user_override = TRUE;
			mono_array_setref (ret, len++, culture);
		}
	}

	return ret;

fail:
	mono_error_set_pending_exception (&error);
	return ret;
}