I want to test the implementation of NSUncaughtExceptionHandler
. What I've tried:
int[] array = new int[3];
array[4] = 1;
object o = null;
o.GetHashCode();
This is my implementation in 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);
}
The exception is not caught. How can I raise an exception, which NSUncaughtExceptionHandler
can catch?