elmah也处理了异常 [英] Does elmah handle caught exceptions as well

查看:147
本文介绍了elmah也处理了异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ELMAH 是否记录了例外情况,即使他们不鼓励应用程序?当异常发生时,我想弹出一条消息,并且仍然记录异常。目前,我一直把所有内容都放在try块中,然后吐出消息,但这样做很繁琐。

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

这篇关于elmah也处理了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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