2010-03-16 70 views
1

我想在一些HandleErrorAttribute類中管理所有的異常。 但對於一些特定的異常類型我想忽略或取消例外HANDELING 和只是繼續與父請求 ..如何用HandleErrorAttribute異常事件忽略異常

感謝

+0

我希望做同樣的事情。當調用異常過濾器時,在某些情況下,只需將控制權交給預期的目標控制器操作方法即可。任何解決方案?指出的解決方案不解決這種情況/行爲。 – 2016-01-26 18:57:18

回答

0

對於那些特定類型或不同類型的異常你希望忽略,你不要將ExceptionHandled標誌設置爲true。

順便說一句,你必須創建一個自定義的ErrorHandler。這可能是這樣的(僞代碼):

public class CustomHandleErrorAttribute : FilterAttribute, IExceptionFilter 
{ 
    public void OnException(ExceptionContext filterContext) 
    { 
     //filterContext.ExceptionHandled = exception_is_of_type_that_must_be_handled; 
     //Other code, logging, etc    
    } 
} 
0

我想忽略一個特定的異常,並與操作方法繼續將趕在你的控制器的具體異常並忽略它存在的唯一方式。

E.g.

[HandleErrorAttribute] 
public ActionResult YourActionMethod() 
{ 
    try 
    { 
     //Do some stuff 
    } 
    catch (SpecificExceptionToIgnore ex) 
    { 
     //Do something here with the exception 
     //E.g. Simply ignore it, Log it, set some modelstate or tempdata 
    } 

    //Carry on. 
    //All other exceptions will be thrown as normal and 
    //will be handled by your 'HandleErrorAttribute' attribute. 

    return View(); 
} 

HTHS,
查爾斯