我已经为Xamarin.Forms
编写了自定义异常处理程序,但我注意到并不是所有的异常都能被捕获。例如。这不是(摘自Xcode>设备和模拟器中的设备日志):
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Application Specific Information:
abort() called
Filtered syslog:
None found
Thread 0 name: tid_303 Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x0000000180d3d2e0 __pthread_kill + 8
1 libsystem_pthread.dylib 0x0000000180ede288 pthread_kill$VARIANT$mp + 376
2 libsystem_c.dylib 0x0000000180cabdb0 __abort + 152
...
异常处理程序类似于this post或this post。它使用NSSetUncaughtExceptionHandler
,AppDomain.CurrentDomain.UnhandledException
,TaskScheduler.UnobservedTaskException
和AsyncSynchronizationContext.ExceptionCaught
。
我没有像示例中那样在FinishedLaunching()
中初始化,但我不认为这是原因。
是否可以在EXC_CRASH (SIGABRT)
中捕获Xamarin.iOS
异常?如果是,该怎么办?
答案 0 :(得分:1)
您可能想使用运行时框架查看Xamarin.iOS 例外封送处理,以及如何使用构建时间标志(mtouch
)将处理程序安装到应用程序中:
Runtime.MarshalObjectiveCException += (object sender, MarshalObjectiveCExceptionEventArgs args) =>
{
Console.WriteLine ("Marshaling Objective-C exception");
Console.WriteLine (" Exception: {0}", args.Exception);
Console.WriteLine (" Mode: {0}", args.ExceptionMode);
};
--marshal-objectivec-exceptions=
default
unwindmanagedcode
throwmanagedexception
abort
disable
re:https://docs.microsoft.com/en-us/xamarin/ios/platform/exception-marshaling