获取 Xamarin Android 中未处理异常的详细异常信息

编程入门 行业动态 更新时间:2024-10-18 10:30:56
本文介绍了获取 Xamarin Android 中未处理异常的详细异常信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如果我在 Xamarin Android 中遇到未处理的异常,就像在使用 Visual Studio 调试时一样,我会收到以下弹出窗口:

If I get an unhandled exception in Xamarin Android, like always when debugging with Visual Studio, I get the following popup:

如果我点击复制详细信息,我会得到

If I click Copy Details I get

未处理的异常:System.AggregateException:发生一个或多个错误.发生

Unhandled Exception: System.AggregateException: One or more errors occurred. occurred

如何深入了解内部异常?

How can I drill down into the inner exceptions?

推荐答案

这是我们的一个应用程序的片段,我们只是针对当前域的 UnhandledException 事件创建一个委托,我们在应用程序的MainApplication"类中执行此操作(有些人在没有实现生命周期回调插件的情况下使用MainActivity").

Here's a snippet from one of our applications, we simply create a delegate against the UnhandledException event for the current domain, we do this within our applications 'MainApplication' class (Some people use 'MainActivity' instead if they have not implemented the lifecycle call back plugin).

基本上,无论您是应用程序的主要起点,您都希望在哪个类中执行此操作.

Basically you want to do this in whichever class is you're applications primary starting point.

作为参考,'ApplicationLog' 只是我创建的一个类,用于将文件目录写入日志文件,您可以在该类中做任何您想做的事情,这里的关键是 'e' 将包含您的堆栈跟踪信息.

For reference 'ApplicationLog' is just a class I created to write to a file directory into a log file, you can do whatever you want inside this class, the key here is that 'e' will contain your stack trace information.

关于您是个例外,值得注意的是,AggregateException 最常由任务中的代码、并行 ForEach 语句甚至 SQL 命令等引发.

Regards you're exception it is worth noting that an AggregateException is most commonly thrown by code within a Task, or Parallel ForEach statements, or even SQL commands etc.

希望这会有所帮助.

            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
            {
                // Record the error in our application logs
                ApplicationLog.AppendFile(
                    DateTime.Now.ToString() + "  :  " + "[CRITICAL GLOBALLY HANDLED EXCEPTION] - Critical exception has been hit! - Message: " + e.ExceptionObject +
                        System.Environment.NewLine + System.Environment.NewLine +
                            "========= Critcal Error has been hit, application closed =========" +
                                System.Environment.NewLine + System.Environment.NewLine
                    );
            };

这篇关于获取 Xamarin Android 中未处理异常的详细异常信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-24 17:48:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068484.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   中未   详细   信息   Xamarin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!