在.NET异常如何获得与参数值堆栈跟踪堆栈、如何获得、异常、参数

2023-09-02 21:28:00 作者:清明时节

我尝试添加未处理的异常处理程序在.NET(C#)应尽可能有益的用户的可能。终端用户大多是编程人员,使他们只需要哪些对象是他们操纵错误的暗示。

I am trying to add an unhandled exception handler in .net (c#) that should be as helpfull for the 'user' as possible. The end users are mostly programers so they just need a hint of what object are they manipulating wrong.

我正在开发一个Windows类似于Windows XP的错误报告,当应用程序崩溃,但是,让imediatly有关抛出的异常之多imediate信息成为可能。

I'm developing a windows similar to the windows XP error report when an application crashes but that gives as much imediate information as possible imediatly about the exception thrown.

虽然堆栈跟踪使我(因为我源$ C ​​$ C),以找出问题的根源,用户没有它,所以他们都将丢失没有进一步的信息。不用说,我不得不花费很多时间支持工具。

While the stack trace enables me (since I have the source code) to pinpoint the source of the problem, the users dont have it and so they are lost without further information. Needless to say I have to spend lots of time supporting the tool.

有几个系统异常喜欢KeyNotFoundException抛出字典集合,真正的错误我,因为他们没有在邮件中包括wasnt发现的关键。我可以填补我的code与吨的try catch块,但其相当侵略性,是其它更多code来维持,更不用提一吨多的不得不最终被本地化字符串。

There are a few system exceptions like KeyNotFoundException thrown by the Dictionary collection that really bug me since they dont include in the message the key that wasnt found. I can fill my code with tons of try catch blocks but its rather agressive and is lots more code to maintain, not to mention a ton more of strings that have to end up being localized.

最后的问题是:有没有什么方法来获得(在运行时)的调用堆栈跟踪每个函数的参数的值? 这本身就可以解决90%的支持电话。

Finally the question: Is there any way to obtain (at runtime) the values of the arguments of each function in the call stack trace? That alone could resolve 90% of the support calls.

推荐答案

我不认为System.Diagnostics.StackFrame提供的参数信息(比方法签名等)。

I don't think System.Diagnostics.StackFrame supplies argument information (other than the method signature).

您可以用仪器跟踪记录通过AOP麻烦的电话,甚至用它的异常拦截功能来有条件地登录,而无需窝您code。有大约 http://www.postsharp.org/ 。

You could instrument the troublesome calls with trace logging via AOP, or even use its exception interception features to conditionally log without having to litter your code. Have a look around http://www.postsharp.org/.