mono-api-exc.html

Exception Handling

void mono_raise_exception (MonoException *ex) ; void mono_unhandled_exception (MonoObject *exc); void mono_print_unhandled_exception (MonoObject *exc); MonoException* mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image, ; MonoException* mono_exception_from_name (MonoImage *image, const char *name_space; MonoException* mono_exception_from_name_msg (MonoImage *image, const char *name_space; MonoException* mono_exception_from_name_two_strings (MonoImage *image, const char *name_space; MonoException* mono_get_exception_appdomain_unloaded (void); MonoException* mono_get_exception_argument (const char *arg, const char *msg); MonoException* mono_get_exception_argument_null (const char *arg); MonoException* mono_get_exception_argument_out_of_range (const char *arg); MonoException* mono_get_exception_arithmetic (); MonoException* mono_get_exception_array_type_mismatch (); MonoException* mono_get_exception_bad_image_format (const char *msg); MonoException* mono_get_exception_cannot_unload_appdomain (const char *msg); MonoException* mono_get_exception_divide_by_zero (); MonoException* mono_get_exception_execution_engine (const char *msg); MonoException* mono_get_exception_file_not_found2 (const char *msg, MonoString *fname); MonoException* mono_get_exception_file_not_found (MonoString *fname); MonoException* mono_get_exception_index_out_of_range (); MonoException* mono_get_exception_invalid_cast (); MonoException* mono_get_exception_io (const char *msg); MonoException* mono_get_exception_missing_method (const char *class_name, const char *member_name); MonoException* mono_get_exception_not_implemented (const char *msg); MonoException* mono_get_exception_null_reference (); MonoException* mono_get_exception_overflow (); MonoException* mono_get_exception_security (); MonoException* mono_get_exception_serialization (const char *msg); MonoException* mono_get_exception_stack_overflow (void); MonoException* mono_get_exception_synchronization_lock (const char *msg); MonoException* mono_get_exception_thread_abort (); MonoException* mono_get_exception_thread_state (const char *msg); MonoException* mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner); MonoException* mono_get_exception_type_load (MonoString *class_name, char *assembly_name); MonoException* mono_get_exception_invalid_operation (const char *msg); MonoException* mono_get_exception_missing_field (const char *class_name, const char *member_name); MonoException* mono_get_exception_not_supported (const char *msg); MonoException* mono_get_exception_reflection_type_load (MonoArray *types, MonoArray *exceptions);

Raising and Catching exceptions

mono_raise_exception
void mono_raise_exception (MonoException *ex)

Parameters

ex:
exception object
Remarks

Signal the runtime that the exception ex has been raised in unmanaged code.

mono_unhandled_exception
void mono_unhandled_exception (MonoObject *exc)

Parameters

exc:
exception thrown
Remarks

This is a VM internal routine. We call this function when we detect an unhandled exception in the default domain. It invokes the * UnhandledException event in AppDomain or prints a warning to the console

mono_print_unhandled_exception
void mono_print_unhandled_exception (MonoObject *exc)

Parameters

exc:
The exception
Remarks

Prints the unhandled exception.

Exception Types: General API

mono_exception_from_name_domain
MonoException* mono_exception_from_name_domain (MonoDomain *domain, MonoImage *image, const char* name_space, const char *name)

Parameters

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
Returns
the initialized exception instance.
Remarks

Creates an exception object of the given namespace/name class on the given domain.

mono_exception_from_name
MonoException* mono_exception_from_name (MonoImage *image, const char *name_space, const char *name)

Parameters

image:
the Mono image where to look for the class
name_space:
the namespace for the class
name:
class name
Returns
the initialized exception instance.
Remarks

Creates an exception of the given namespace/name class in the current domain.

mono_exception_from_name_msg
MonoException* mono_exception_from_name_msg (MonoImage *image, const char *name_space, const char *name, const char *msg)

Parameters

image:
the Mono image where to look for the class
name_space:
the namespace for the class
name:
class name
msg:
the message to embed inside the exception
Returns
the initialized exception instance.
Remarks

Creates an exception and initializes its message field.

mono_exception_from_name_two_strings
MonoException* mono_exception_from_name_two_strings (MonoImage *image, const char *name_space, const char *name, MonoString *a1, MonoString *a2)

Parameters

image:
the Mono image where to look for the class
name_space:
the namespace for the class
name:
class name
a1:
first string argument to pass
a2:
second string argument to pass
Returns
the initialized exception instance.
Remarks

Creates an exception from a constructor that takes two string arguments.

Obtaining Common Exceptions

There are a number of common exceptions that are used by the runtime, use the routines in this section to get a copy of those exceptions.

mono_get_exception_appdomain_unloaded
MonoException* mono_get_exception_appdomain_unloaded (void)

Returns

a new instance of the System.AppDomainUnloadedException
mono_get_exception_argument
MonoException* mono_get_exception_argument (const char *arg, const char *msg)

Parameters

arg:
the name of the invalid argument.
Returns
a new instance of the System.ArgumentException
mono_get_exception_argument_null
MonoException* mono_get_exception_argument_null (const char *arg)

Parameters

arg:
the name of the argument that is null
Returns
a new instance of the System.ArgumentNullException
mono_get_exception_argument_out_of_range
MonoException* mono_get_exception_argument_out_of_range (const char *arg)

Parameters

arg:
the name of the out of range argument.
Returns
a new instance of the System.ArgumentOutOfRangeException
mono_get_exception_arithmetic
MonoException* mono_get_exception_arithmetic ()

Returns

a new instance of the System.ArithmeticException.
mono_get_exception_array_type_mismatch
MonoException* mono_get_exception_array_type_mismatch ()

Returns

a new instance of the System.ArrayTypeMismatchException
mono_get_exception_bad_image_format
MonoException* mono_get_exception_bad_image_format (const char *msg)

Parameters

msg:
an informative message for the user.
Returns
a new instance of the System.BadImageFormatException
mono_get_exception_cannot_unload_appdomain
MonoException* mono_get_exception_cannot_unload_appdomain (const char *msg)

Parameters

inner:
the inner exception.
Returns
a new instance of the System.CannotUnloadAppDomainException
mono_get_exception_class
Prototype: mono_get_exception_class

mono_get_exception_divide_by_zero
MonoException* mono_get_exception_divide_by_zero ()

Returns

a new instance of the System.DivideByZeroException
mono_get_exception_execution_engine
MonoException* mono_get_exception_execution_engine (const char *msg)

Parameters

msg:
the message to pass to the user
Returns
a new instance of the System.ExecutionEngineException
mono_get_exception_file_not_found2
MonoException* mono_get_exception_file_not_found2 (const char *msg, MonoString *fname)

Parameters

msg:
an informative message for the user.
fname:
the name of the file not found.
Returns
a new instance of the System.IO.FileNotFoundException
mono_get_exception_file_not_found
MonoException* mono_get_exception_file_not_found (MonoString *fname)

Parameters

fname:
the name of the file not found.
Returns
a new instance of the System.IO.FileNotFoundException
mono_get_exception_index_out_of_range
MonoException* mono_get_exception_index_out_of_range ()

Returns

a new instance of the System.IndexOutOfRangeException
mono_get_exception_invalid_cast
MonoException* mono_get_exception_invalid_cast ()

Returns

a new instance of the System.InvalidCastException
mono_get_exception_io
MonoException* mono_get_exception_io (const char *msg)

Parameters

msg:
the message to present to the user
Returns
a new instance of the System.IO.IOException
mono_get_exception_missing_method
MonoException* mono_get_exception_missing_method (const char *class_name, const char *member_name)

Parameters

class_name:
the class where the lookup was performed.
member_name:
the name of the missing method.
Returns
a new instance of the System.MissingMethodException
mono_get_exception_not_implemented
MonoException* mono_get_exception_not_implemented (const char *msg)

Parameters

msg:
the message to pass to the user
Returns
a new instance of the System.NotImplementedException
mono_get_exception_null_reference
MonoException* mono_get_exception_null_reference ()

Returns

a new instance of the System.NullReferenceException
mono_get_exception_overflow
MonoException* mono_get_exception_overflow ()

Returns

a new instance of the System.OverflowException
mono_get_exception_security
MonoException* mono_get_exception_security ()

Returns

a new instance of the System.Security.SecurityException
mono_get_exception_serialization
MonoException* mono_get_exception_serialization (const char *msg)

Parameters

msg:
the message to pass to the user
Returns
a new instance of the System.Runtime.Serialization.SerializationException
mono_get_exception_stack_overflow
MonoException* mono_get_exception_stack_overflow (void)

Returns

a new instance of the System.StackOverflowException
mono_get_exception_synchronization_lock
MonoException* mono_get_exception_synchronization_lock (const char *msg)

Parameters

inner:
the inner exception.
Returns
a new instance of the System.SynchronizationLockException
mono_get_exception_thread_abort
MonoException* mono_get_exception_thread_abort ()

Returns

a new instance of the System.Threading.ThreadAbortException.
mono_get_exception_thread_state
MonoException* mono_get_exception_thread_state (const char *msg)

Parameters

msg:
the message to present to the user
Returns
a new instance of the System.Threading.ThreadStateException
mono_get_exception_type_initialization
MonoException* mono_get_exception_type_initialization (const gchar *type_name, MonoException *inner)

Parameters

type_name:
the name of the type that failed to initialize.
inner:
the inner exception.
Returns
a new instance of the System.TypeInitializationException
mono_get_exception_type_load
MonoException* mono_get_exception_type_load (MonoString *class_name, char *assembly_name)

Parameters

class_name:
the name of the class that could not be loaded
assembly_name:
the assembly where the class was looked up.
Returns
a new instance of the System.TypeLoadException.
mono_get_exception_invalid_operation
MonoException* mono_get_exception_invalid_operation (const char *msg)

Parameters

msg:
the message to pass to the user
Returns
a new instance of the System.InvalidOperationException
mono_get_exception_missing_field
MonoException* mono_get_exception_missing_field (const char *class_name, const char *member_name)

Parameters

class_name:
the class where the lookup was performed
member_name:
the name of the missing method.
Returns
a new instance of the System.MissingFieldException
mono_get_exception_not_supported
MonoException* mono_get_exception_not_supported (const char *msg)

Parameters

msg:
the message to pass to the user
Returns
a new instance of the System.NotSupportedException