这个链接描述了如何在 iOS 中处理异常
Runtime.MarshalManagedException += (object sender, MarshalManagedExceptionEventArgs args) =>
{
Console.WriteLine ("Marshaling managed exception");
Console.WriteLine (" Exception: {0}", args.Exception);
Console.WriteLine (" Mode: {0}", args.ExceptionMode);
};
Runtime.MarshalObjectiveCException += (object sender, MarshalObjectiveCExceptionEventArgs args) =>
{
Console.WriteLine ("Marshaling Objective-C exception");
Console.WriteLine (" Exception: {0}", args.Exception);
Console.WriteLine (" Mode: {0}", args.ExceptionMode);
};
此外,我还看到其他 Xamarin 示例在 AppDelegate 中使用它
AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
try
{
var exception = ((Exception)e.ExceptionObject).GetBaseException();
Console.WriteLine("**SPORT UNHANDLED EXCEPTION**\n\n" + exception);
exception.Track();
}
catch
{
throw;
}
};
问题
异常类型是什么(如果超过托管/非托管),我如何捕获所有内容?