c# - 异常后C#中局部变量的值?

标签 c# .net debugging

RedGate 有一个 error reporting tool那说它可以

"Get a complete state of your program when it crashed (not just the stack trace), including the values of variables when the crash happened – without having to go back and forth in inefficient email conversations with the end-user."



我已经为我们的应用程序构建了一个未处理的异常报告工具,但我无法想象它们如何在生产代码中获得比堆栈跟踪信息更多的信息。

有没有人有任何想法?

最佳答案

看起来他们所做的是重写您的程序集并在每个方法中添加一个 try/catch 块(除了您明确排除的那些)。 catch 获取所有局部变量的值。所以如果我有代码:

private int Add(int o1, int o2) {
  return o1+o2;
}

它会将其修改为:
private int Add(int o1, int o2) {
  int ret = 0;
  try {
    ret = o1+o2;
  }
  catch (Exception e) {
    SpecialExceptionHandler.HandleException(e, new object[]{o1, o2});
  }
  return ret;
}

相当棘手......因此,它将在异常发生时显示参数和本地人的值。

关于c# - 异常后C#中局部变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3087595/

相关文章:

c# - 如何获取网页内容并将其保存到字符串变量中

c# - SslStream.AuthenticateAsClient - 发送时无法立即完成非阻塞套接字操作

java - Eclipse Java 调试器源查找路径

matlab - MATLAB 是否有任何显示向量和矩阵维度的 Debug模式?

c# - 如何找到 "out of range"异常的原因?

c# - C# 中真随机数生成器的最快实现

c# - 在基于 View 的WPF应用程序中从ViewModel更改 View

c# - 我想从 C# 创建 xlsx ( Excel ) 文件

c# - 使用 LINQ 在 XML 中的特定位置插入特定的 XElement

C# ArrayList 调用构造函数类