c# - Application_DispatcherUnhandledException 问题
问题描述
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show($"e.Exception?.Message}\n*********\n*e.Exception?.Data.ToString()}**********{e.Exception.StackTrace}");
e.Handled = true;
}
我在 App.xaml.cs 中使用上述代码来捕获我的代码中未处理的任何错误。如果消息是:已添加具有相同键的项目。因为我试图在字典中插入一个现有的键,我怎么知道它是哪个字典?那是在 e 的某个地方吗?谢谢弗兰克
解决方案
简短的回答:你不会。
CLR 不在别处存储变量的名称。这里给出了解释:Getting the variable name for NullReferenceException。
但是您可以检查e.data
具有Keys
和Values
属性的对象,因此您可以猜测哪个实例 cas 具有此值。
此外,您可以获得有关引发异常的源代码行的信息:如何获取导致异常的方法的名称
推荐阅读
- mysql - 如何在 Laravel 列中获取不同 ID/元素的总和?
- flutter - 在 Flutter 中添加 Profile 图标
- javascript - 从背景颜色中获取 RGB 分量
- tensorflow - 使用神经网络的一类图像分类
- unit-testing - Spock交互验证忽略对Mock方法的调用
- c# - 无法从 ASP.NET IdentityUserRole 中提取具有角色的用户列表
- c# - 您可以将 X 值更改为 MySQL 行中的相应值吗?
- wordpress - 选择本地取货作为交货时未出现 Woocommerce 税
- java - Gradle 插件:无法将 Java.io.File 类的“A.txt”转换为 org.gradle.api.file.Property 类
- python - 使用 python 标记日志到 gcp 日志查看器