Getting on with your life – MVC error handling witchcraft

Let’s say, theoretically of course, that you just wanted to swallow a particular error that seemed like it should be easy to fix, but it isn’t, and you just want to get on with your life and perhaps, someday, figure it out later. I know, you would never do this. But if you had a friend using MVC, and they wanted to do this, here is how I would suggest they do it using the OnException method:

        protected override void OnException(ExceptionContext filterContext) {
            if (filterContext.Exception.Message.Contains("stupid error")) {
                filterContext.ExceptionHandled = true; 
                filterContext.Result = new ViewResult {
                    ViewName = "~/Views/Home/Index.cshtml"




  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: