在.net异常如何获取一个具有参数值的堆栈跟踪 [英] In a .net Exception how to get a stacktrace with argument values

查看:236
本文介绍了在.net异常如何获取一个具有参数值的堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在.net(c#)中添加一个未处理的异常处理程序,它应该尽可能地帮助'用户'。最终用户大多是编程人员,所以他们只需要一些提示他们操作错误的对象。



我正在开发一个类似Windows XP错误报告的窗口应用程序崩溃,但是尽可能地给出了抛出异常的imediate信息。



虽然堆栈跟踪使我(因为我有源代码)来确定源的问题,用户没有它,所以他们丢失没有进一步的信息。不用说,我必须花很多时间支持这个工具。



有一些系统异常,如Dictionary集合抛出的KeyNotFoundException,真的让我失望,因为他们不包括在消息中没有找到的关键。我可以用大量的try catch来填充我的代码,但是它比较有吸引力,而且还有更多的维护代码,更不用说多一些字符串必须最终被本地化了。



最后一个问题是:有什么办法获取(在运行时)调用堆栈跟踪中每个函数的参数的值?
这可以解决90%的支持电话。

解决方案

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



您可以通过AOP对跟踪记录进行麻烦的调用,甚至使用其异常拦截功能有条件地记录,而无需丢弃代码。查看 http://www.postsharp.org/


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.

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.

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.

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.

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.

解决方案

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

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/.

这篇关于在.net异常如何获取一个具有参数值的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆