获取的参数堆栈跟踪值堆栈、参数

由网友(我历史不好别跟我提曾经)分享简介:我无法重现,我们看到在我们的错误日志中的一些错误。I am having trouble reproducing a few errors we are seeing in our error log.这可以作出一个容易得多,如果我知道哪个记录ID的具体方法是使用时,它抛出一个异常。It could be mad...

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

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);
    }
}
阅读全文

相关推荐

最新文章