【发布时间】:2016-09-28 13:13:12
【问题描述】:
我想测试NSUncaughtExceptionHandler 的实现。我试过的:
int[] array = new int[3];
array[4] = 1;
object o = null;
o.GetHashCode();
这是我在 AppDelegate.cs 中的实现:
public delegate void NSUncaughtExceptionHandler(IntPtr handle);
[DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
private static extern void NSSetUncaughtExceptionHandler(IntPtr handle);
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
NSSetUncaughtExceptionHandler(Marshal.GetFunctionPointerForDelegate(new NSUncaughtExceptionHandler(MyUncaughtExceptionHandler)));
return base.FinishedLaunching(app, options);
}
[MonoPInvokeCallback(typeof(NSUncaughtExceptionHandler))]
private static void MyUncaughtExceptionHandler(IntPtr handle)
{
NSException exception = (NSException)ObjCRuntime.Runtime.GetNSObject(handle);
}
异常未被捕获。如何引发 NSUncaughtExceptionHandler 可以捕获的异常?
【问题讨论】:
标签: c# ios xamarin exception-handling xamarin.ios