我可以自动抛出带有参数值和类字段信息的描述性异常吗?

发布于 2024-08-29 09:24:12 字数 388 浏览 4 评论 0原文

老实说,我不经常抛出异常。讽刺的是,我抓到的人更少。我目前在商店工作,我们让它们冒泡到 avicode。然而,无论出于何种原因,当这些异常重新引起我的注意时,avicode 都没有配置为捕获我需要的一些关键位。具体来说,我想查看异常发生时的参数值和类的字段数据。

我猜想,通过大量的 .Net 服务,我可以创建一个静态方法来爬行堆栈,收集这些位并将它们存储在一个字符串中,我可以将其粘贴在异常消息中。我真的不知道这样的方法需要多长时间才能执行,因为当我遇到其中一种情况时,性能不再是问题。

如果可能的话,我确信有人已经做到了。如果是这样的话,我就很难找到它了。我认为任何包含“例外”的搜索都会返回太多结果。

无论如何,这可以做到吗?如果是这样,一些示例或链接会很棒。

预先感谢您的宝贵时间, 罗伯特

I honestly don't throw exceptions often. I catch them even less, ironically. I currently work in shop where we let them bubble up to avicode. For whatever reason, however, avicode isn't configured to capture some of the critical bits I need when these exceptions come bouncing back to my attention. Specifically, I'd like to see the parameter values and the class’s field data at the time of the exception.

I’d guess with the large suite of .Net services that I could create a static method to crawl up the stack, gather these bits and store them in a string that I could stick in my exception message. I really don't are how long such a method would take to execute as performance is no longer a concern when I hit one of these scenarios.

If it's possible, I'm sure someone has done it. If that's the case, I'm having a hard time finding it. I think any search containing "exception" brings back too many resutls.

Anyway, can this be done? If so, some examples or links would be great.

Thanks in advance for your time,
Robert

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〃温暖了心ぐ 2024-09-05 09:24:12

我准备在这一点上犯错,但我认为不可能通过遍历堆栈来提取参数值。您当然不能使用 StackTrace 和 < a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe.aspx" rel="nofollow noreferrer">StackFrame 类。

从安全角度来看,这是有道理的,因为敏感信息可能嵌入到未经授权的代码不应访问的堆栈中。

如果当前堆栈帧在重新抛出之前没有捕获异常并将其参数值记录到 Exception 实例中,那么我担心您会不走运。

I am prepared to be wrong about this, but I do not think it is possible to extract parameter values by walking the stack. You certainly cannot do this with the StackTrace and StackFrame classes.

From a security perspective this makes sense because sensitive information could be embedded in the stack that unauthorized code should not have access to.

If the current stack frame does not catch the exception and record its parameter values into an Exception instance before rethrowing then I am afraid you are going to be out of luck.

猫腻 2024-09-05 09:24:12

我认为您可以使用 CLR 调试 API 来获取更多信息,而不仅仅是堆栈跟踪,但我认为这并不容易。
http://msdn.microsoft.com/en-us/library/bb384548。 ASPX

I think you can use the CLR Debugging API to get out some more information than just the stacktrace, but I don't think it's easy.
http://msdn.microsoft.com/en-us/library/bb384548.aspx

桃气十足 2024-09-05 09:24:12

不确定这是否正是您正在寻找的,但作为 AVIcode 的顾问,我可以保证这是一个简单的配置更改,可以按命名空间、类或方法收集参数和成员变量。您甚至可以配置诊断模式并收集局部变量。该应用程序已投入生产吗?在生产中,但我会特定于一个类来启用。

Not sure if this is exactly what you are looking for, but as a consultant for AVIcode I can assure that it is a simple configuration change to collect parameters and member variables by namespace, class or method. You can even go as far as configuring diagnostic mode and collect local variables. Is this application in production? In production but I would be specific to a class to enable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文