MonoTouch: uncaughtExceptionHandler?

前端 未结 3 452
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 10:19

In MonoTouch, how do I register an uncaught exception handler (or similar function)

In Obj-C:

void uncaughtExceptionHandler(NSException *exception) {         


        
3条回答
  •  别那么骄傲
    2021-01-12 10:42

        public delegate void NSUncaughtExceptionHandler(IntPtr exception);
    
        [DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
        private static extern void NSSetUncaughtExceptionHandler(IntPtr handler);
    
        // This is the main entry point of the application.
        private static void Main(string[] args)
        {
                NSSetUncaughtExceptionHandler(
                    Marshal.GetFunctionPointerForDelegate(new NSUncaughtExceptionHandler(MyUncaughtExceptionHandler)));
    
                ...
        }
    
        [MonoPInvokeCallback(typeof(NSUncaughtExceptionHandler))]
        private static void MyUncaughtExceptionHandler(IntPtr exception)
        {
            var e = new NSException(exception);
            ...
        }
    

提交回复
热议问题