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)
        {
            base.OnException(filterContext);
            Exception e = filterContext.Exception;
            //loging(e.Message.ToString());
            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