---
title: "How to HandlError in mvc?"  
description: "How to HandlError in mvc?"  
author: "Anonymous User"  
published: 2014-10-29  
updated: 2014-10-29  
canonical: https://www.mindstick.com/forum/2457/how-to-handlerror-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc", "mvc4"]  
reading_time: 2 minutes  

---

# How to HandlError in mvc?

How do I go about the [[HandleError](https://www.mindstick.com/forum/2325/how-do-mvc-handleerror)] [filter in asp.net](https://www.mindstick.com/forum/156904/what-is-authorization-filter-in-asp-dot-net-mvc) MVC [Preview](https://www.mindstick.com/forum/429/i-want-to-get-full-path-of-lt-asp-fileupload-gt-and-then-client-can-click-the-preview-button-to-see-what-file-he-here-has-uploaded) 5?I set the customErrors in my [Web.config](https://www.mindstick.com/forum/183/web-config-file) file\

```
<customErrors mode="On" defaultRedirect="Error.aspx">  <error statusCode="403" redirect="NoAccess.htm"/>  <error statusCode="404" redirect="FileNotFound.htm"/></customErrors>
```

and put [HandleError] above my [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) Class like this:\

```
[HandleError]    public class DSWebsiteController : Controller { [snip] public ActionResult CrashTest() { throw new Exception("Oh Noes!"); } }
```

Then I let my [controllers](https://www.mindstick.com/forum/155773/how-asynchronous-controllers-work-in-asp-dot-net-mvc) inherit from this class and call CrashTest() on them. [Visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) halts at the error and after pressing f5 to continue, I get rerouted to Error.aspx?aspxerrorpath=/sxi.mvc/CrashTest (where sxi is the name of the used controller. Off course the path cannot be found and I get "[Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) Error in '/' Application." 404.\

## Replies

### Reply by Barbara Jones

[HandleError]

When you provide only the HandleError attribute to your class (or to your action method for that matter), then when an unhandled exception occurs MVC will look for a corresponding View named "Error" first in the Controller's View folder. If it can't find it there then it will proceed to look in the Shared View folder (which should have an Error.aspx file in it by default)\

```
[HandleError(ExceptionType = typeof(SqlException), View = "DatabaseError")]][HandleError(ExceptionType = typeof(NullReferenceException), View = "LameErrorHandling")]]
```

You can also stack up additional attributes with specific information about the type of exception you are looking for. At that point, you can direct the Error to a specific view other than the default "Error" view.\


---

Original Source: https://www.mindstick.com/forum/2457/how-to-handlerror-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
