Hi, I want to manage all of my exceptions in some HandleErrorAttribute class. but for some specific exceptions types i want to ignore or cancel the exceptions handeling and just continue with the parent request..
thanks
Hi, I want to manage all of my exceptions in some HandleErrorAttribute class. but for some specific exceptions types i want to ignore or cancel the exceptions handeling and just continue with the parent request..
thanks
For those exceptions which are of the specific type or types you wish to ignore, you don´t set the ExceptionHandled flag in true.
By the way, you have to create a custom ErrorHandler. It could be something like this (pseudo code):
public class CustomHandleErrorAttribute : FilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
//filterContext.ExceptionHandled = exception_is_of_type_that_must_be_handled;
//Other code, logging, etc
}
}
I think the only way to ignore a specific exception and continue with the action method would be to catch the specific exception in your controller and ignore it there.
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,
Charles