我的答案是不
为什么?
关于大自然,您必须了解一件重要的事情
Android 中未处理的异常,在 Android 中没有……
这是一个未捕获的异常,这意味着您无法“处理”它或
像在 .Net 环境中那样从它中恢复。
Xamarin(Mono) 在内部“处理”那些未捕获的异常
用 try-catch 包围一切并提高
未处理的事件,但这不是重点。也很气馁
出于各种原因与 UI 进行交互。
理论上,显示对话框有几种“变通方法”
给用户或重新启动应用程序,我不建议这样做
正在做。相反,您应该使用 try-catch 包围敏感区域
处理预期异常的子句,至于意外的
只需使用异常报告组件并在之后更新您的应用程序
分析报告的异常
解释From
您也可以像这样从应用程序中捕获未处理的异常
创建一个类似名称的基础活动 ErrorActivity
看看这个例子
protected override void OnCreate(Bundle bundle)
{
//register error handlers
AppDomain.CurrentDomain.UnhandledException += ErrorHandler.CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += ErrorHandler.TaskSchedulerOnUnobservedTaskException;
}
在错误处理类中
public static class ErrorHandler
{
/// <summary>
/// Tasks the scheduler on unobserved task exception.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="unobservedTaskExceptionEventArgs">
/// The <see cref="UnobservedTaskExceptionEventArgs" /> instance containing
/// the event data.
/// </param>
public static void TaskSchedulerOnUnobservedTaskException(object sender,
UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
{
var newExc = new Exception("TaskSchedulerOnUnobservedTaskException",
unobservedTaskExceptionEventArgs.Exception);
LogUnhandledException(newExc);
}
/// <summary>
/// Currents the domain on unhandled exception.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="unhandledExceptionEventArgs">
/// The <see cref="UnhandledExceptionEventArgs" /> instance containing the event
/// data.
/// </param>
public static void CurrentDomainOnUnhandledException(object sender,
UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
var newExc = new Exception("CurrentDomainOnUnhandledException",
unhandledExceptionEventArgs.ExceptionObject as Exception);
LogUnhandledException(newExc);
}
/// <summary>
/// Logs the unhandled exception.
/// </summary>
/// <param name="exception">The exception.</param>
internal static void LogUnhandledException(Exception exception)
{
try
{
string error =
$"Exception Caught:{DateTime.Now:F} The Error Message IS {exception.Message}\n\r full stack trace is {exception.ToString()} ";
#if DEBUG
const string errorFileName = "errorlog.txt";
var libraryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
// iOS: Environment.SpecialFolder.Resources
var errorFilePath = System.IO.Path.Combine(libraryPath, errorFileName);
System.IO.File.WriteAllText(errorFilePath, error);
Android.Util.Log.Error("Crash Report error not handled", ex.ToString());
#else
// Log to Android Device Logging.
Android.Util.Log.Error("Crash Report", error);
#endif
}
catch (Exception ex)
{
Android.Util.Log.Error("Crash Report error not handled", ex.ToString());
// just suppress any error logging exceptions
}
}
}
现在您可以像这样从 ErrorActivity 继承所有活动
Public class Fooactivity:ErrorActivity
{
}
现在您可以在应用程序中处理错误..因此您可以从日志文件..或 android 设备日志记录监视器中获取错误日志..希望这会有所帮助...