本文介绍了是否ELMAH处理捕获的异常以及的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

记录异常,即使他们不冒泡到应用程序?我想,当发生异常时弹出一个消息,仍然记录异常。目前,我已经把一切都在尝试catch块,并吐出的消息,但是这得乏味。

Does ELMAH logged exceptions even when they do not bubble up to the application? I'd like to pop up a message when an exception occurs and still log the exception. Currently I've been putting everything in try catch blocks and spitting out messages, but this gets tedious.

推荐答案

ELMAH已更新,以支持新的功能,称为的。

ELMAH has been updated to support a new feature called Signaling.

这可以让你处理,你怎么想的例外,同时还记录他们ELMAH。

This allows you to handle exceptions how you want, while still logging them to ELMAH.

try
{
    int i = 5;
    int j = 0;
    i = i / j; //Throws exception
}
catch (Exception ex)
{
    MyPersonalHandlingCode(ex);
    ErrorSignal.FromCurrentContext().Raise(ex); //ELMAH Signaling
}

重新抛出异常可能是一个不好的做法,因为它使人们难以跟踪应用程序的流程。使用信令是一个更好的方法,如果你打算处理以某种方式错误,只是想记录它。

Re-throwing exceptions can be a bad practice as it makes it difficult to trace the flow of an application. Using Signaling is a much better approach if you intended to handle the error in some fashion and simply want to document it.

请检查出ELMAH 这个优秀的导游 DotNetSlackers

Please check out this excellent guide by DotNetSlackers on ELMAH

这篇关于是否ELMAH处理捕获的异常以及的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!