[runtime] Generated binding wrappers that catch ObjC exceptions are supposed to always convert to managed exceptions. (#133)
This commit is contained in:
Родитель
dbf28e763c
Коммит
71f4d78b18
|
@ -1431,6 +1431,13 @@ namespace Xamarin.BindingMethods.Generator
|
|||
writer.WriteLine ("#endif");
|
||||
}
|
||||
|
||||
static void WriteCatchHandler (StringWriter writer)
|
||||
{
|
||||
writer.WriteLine ("\t} @catch (NSException *e) {");
|
||||
writer.WriteLine ("\t\txamarin_process_nsexception_using_mode (e, true);");
|
||||
writer.WriteLine ("\t}");
|
||||
}
|
||||
|
||||
static void Write_objc_msgSend (StringWriter writer, FunctionData func)
|
||||
{
|
||||
// func name
|
||||
|
@ -1499,11 +1506,8 @@ namespace Xamarin.BindingMethods.Generator
|
|||
}
|
||||
|
||||
// @catch
|
||||
if (func.MarshalExceptions) {
|
||||
writer.WriteLine ("\t} @catch (NSException *e) {");
|
||||
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
|
||||
writer.WriteLine ("\t}");
|
||||
}
|
||||
if (func.MarshalExceptions)
|
||||
WriteCatchHandler (writer);
|
||||
|
||||
writer.WriteLine ("}");
|
||||
writer.WriteLine ();
|
||||
|
@ -1577,11 +1581,8 @@ namespace Xamarin.BindingMethods.Generator
|
|||
}
|
||||
|
||||
// @catch
|
||||
if (func.MarshalExceptions) {
|
||||
writer.WriteLine ("\t} @catch (NSException *e) {");
|
||||
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
|
||||
writer.WriteLine ("\t}");
|
||||
}
|
||||
if (func.MarshalExceptions)
|
||||
WriteCatchHandler (writer);
|
||||
|
||||
writer.WriteLine ("}");
|
||||
writer.WriteLine ();
|
||||
|
@ -1651,11 +1652,8 @@ namespace Xamarin.BindingMethods.Generator
|
|||
}
|
||||
|
||||
// @catch
|
||||
if (func.MarshalExceptions) {
|
||||
writer.WriteLine ("\t} @catch (NSException *e) {");
|
||||
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
|
||||
writer.WriteLine ("\t}");
|
||||
}
|
||||
if (func.MarshalExceptions)
|
||||
WriteCatchHandler (writer);
|
||||
|
||||
writer.WriteLine ("}");
|
||||
writer.WriteLine ();
|
||||
|
@ -1725,11 +1723,8 @@ namespace Xamarin.BindingMethods.Generator
|
|||
}
|
||||
|
||||
// @catch
|
||||
if (func.MarshalExceptions) {
|
||||
writer.WriteLine ("\t} @catch (NSException *e) {");
|
||||
writer.WriteLine ("\t\txamarin_process_nsexception (e);");
|
||||
writer.WriteLine ("\t}");
|
||||
}
|
||||
if (func.MarshalExceptions)
|
||||
WriteCatchHandler (writer);
|
||||
|
||||
writer.WriteLine ("}");
|
||||
writer.WriteLine ();
|
||||
|
|
|
@ -161,7 +161,8 @@
|
|||
) { WrappedManagedFunction = "OnMarshalManagedException" },
|
||||
|
||||
new XDelegate ("MarshalObjectiveCExceptionMode", "MarshalObjectiveCExceptionMode", "xamarin_on_marshal_objectivec_exception",
|
||||
"id", "IntPtr", "exception"
|
||||
"id", "IntPtr", "exception",
|
||||
"bool", "bool", "throwManagedAsDefault"
|
||||
) { WrappedManagedFunction = "OnMarshalObjectiveCException" },
|
||||
};
|
||||
delegates.CalculateLengths ();
|
||||
|
|
|
@ -1916,14 +1916,21 @@ xamarin_skip_encoding_flags (const char *encoding)
|
|||
void
|
||||
xamarin_process_nsexception (NSException *ns_exception)
|
||||
{
|
||||
MarshalObjectiveCExceptionMode mode;
|
||||
xamarin_process_nsexception_using_mode (ns_exception, false);
|
||||
}
|
||||
|
||||
void
|
||||
xamarin_process_nsexception_using_mode (NSException *ns_exception, bool throwManagedAsDefault)
|
||||
{
|
||||
XamarinGCHandle *exc_handle;
|
||||
|
||||
mode = xamarin_on_marshal_objectivec_exception (ns_exception);
|
||||
MarshalObjectiveCExceptionMode mode;
|
||||
|
||||
mode = xamarin_on_marshal_objectivec_exception (ns_exception, throwManagedAsDefault);
|
||||
|
||||
if (mode == MarshalObjectiveCExceptionModeDefault)
|
||||
mode = xamarin_is_gc_coop ? MarshalObjectiveCExceptionModeThrowManagedException : MarshalObjectiveCExceptionModeUnwindManagedCode;
|
||||
|
||||
|
||||
switch (mode) {
|
||||
case MarshalObjectiveCExceptionModeUnwindManagedCode:
|
||||
if (xamarin_is_gc_coop)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "mono-runtime.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -146,6 +147,7 @@ void xamarin_set_gc_pump_enabled (bool value);
|
|||
typedef void (*XamarinUnhandledExceptionFunc) (MonoObject *exc, const char *type_name, const char *message, const char *trace);
|
||||
void xamarin_install_unhandled_exception_hook (XamarinUnhandledExceptionFunc func);
|
||||
void xamarin_process_nsexception (NSException *exc);
|
||||
void xamarin_process_nsexception_using_mode (NSException *ns_exception, bool throwManagedAsDefault);
|
||||
void xamarin_process_managed_exception (MonoObject *exc);
|
||||
|
||||
id xamarin_invoke_objc_method_implementation (id self, SEL sel, IMP xamarin_impl);
|
||||
|
|
|
@ -245,14 +245,17 @@ namespace XamCore.ObjCRuntime {
|
|||
public static event MarshalObjectiveCExceptionHandler MarshalObjectiveCException;
|
||||
public static event MarshalManagedExceptionHandler MarshalManagedException;
|
||||
|
||||
static MarshalObjectiveCExceptionMode OnMarshalObjectiveCException (IntPtr exception_handle)
|
||||
static MarshalObjectiveCExceptionMode OnMarshalObjectiveCException (IntPtr exception_handle, bool throwManagedAsDefault)
|
||||
{
|
||||
if (throwManagedAsDefault && MarshalObjectiveCException == null)
|
||||
return MarshalObjectiveCExceptionMode.ThrowManagedException;
|
||||
|
||||
if (MarshalObjectiveCException != null) {
|
||||
var exception = GetNSObject<NSException> (exception_handle);
|
||||
var args = new MarshalObjectiveCExceptionEventArgs ()
|
||||
{
|
||||
Exception = exception,
|
||||
ExceptionMode = objc_exception_mode,
|
||||
ExceptionMode = throwManagedAsDefault ? MarshalObjectiveCExceptionMode.ThrowManagedException : objc_exception_mode,
|
||||
};
|
||||
|
||||
MarshalObjectiveCException (null, args);
|
||||
|
|
Загрузка…
Ссылка в новой задаче