获取的参数堆栈跟踪值 [英] Get values of parameters in stack trace

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

问题描述

我无法重现,我们看到在我们的错误日志中的一些错误。

I am having trouble reproducing a few errors we are seeing in our error log.

这可以作出一个容易得多,如果我知道哪个记录ID的具体方法是使用时,它抛出一个异常。

It could be made a lot easier if I knew which record ID a specific method was using when it threw an exception.

我们的所有未处理的异常,可以通过我们的全球异常处理程序,这使异常的所有细节,以及HTTP请求的所有细节,到日志表处理。

All of our unhandled exceptions get handled by our global exception handler, which puts all the details of the exception, as well as all the details of the HTTP request, into a log table.

有没有一种方法来捕获所有的参数,抛出的异常的方法的价值?甚至更好,所有的值向上堆栈跟踪?

Is there a way to capture the values of all the parameters for the method that threw an exception? Or even better, all the values up the stack trace?

推荐答案

不幸的是,这是不可能的:在当你捕捉到异常处理程序时,所有的方法参数堆栈帧都没有了。一旦控制离开你的功能,你再也不能访问它的参数值。

Unfortunately, this is not possible: at the time when you catch the exception in the handler, all the stack frames with the method parameters are gone. Once the control leaves your function, you can no longer access its parameter values.

既然你知道具体的功能,其中的碰撞发生时,你可以建立一个异常处理程序那里收集相关的所有参数,并重新抛出一个包装异常。一旦诊断是完整的,你可以恢复的code恢复正常:

Since you know the specific function where the crash happens, you could set up an exception handler there to collect all the parameters of interest, and re-throw a wrapped exception. Once the diagnostics is complete, you could revert the code back to normal:

void SuspiciousFunction(string name, long count) {
    try {
        // The code of your function goes here
    } catch (Exception e) {
        var args = new Dictionary<string,object> {
            { "name" , name  }
        ,   { "count", count }
        };
        throw new MySpecialException(e, args);
    }
}

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

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