Wednesday, 26 July 2017

Catch all unhandled exceptions on Controll level

watch this example on YouTube

add this method at the end of your controller

        protected override void OnException(ExceptionContext filterContext)
            Exception e = filterContext.Exception;
            filterContext.ExceptionHandled = true;
            filterContext.Result = new ViewResult()
                ViewName = "Error"

to create dummy exception
       throw new System.ArgumentException("something is wrong");

No comments:

Post a Comment