title: Exception handling in Controller in ASP.Net MVC 4 with ELMAH and ajax
body: <p>I've seen a number of posts and articles but am not able to see the solution crisply.</p>
  
  <p>I've installed Elmah.MVC via NuGet and have commented out this line from FilterConfig.cs:</p>
  
  <pre><code>//filters.Add(new HandleErrorAttribute());
  </code></pre>
  
  <p>So that Elmah would pick up the errors.</p>
  
  <p>It works when I provide an invalid action name and I get a yellow page as well as an email.</p>
  
  <p>I want to know about two other types of errors that my code may generate... how are we supposed to handle them:</p>
  
  <p>1.E.g. if my repository or manager (business logic) layer throws an exception when trying to access database or send an email etc.</p>
  
  <p>a. Is the correct way to NOT implement any kind of try catch in Controllers (or anywhere else for that matter) and let Elmah take care of exceptions? </p>
  
  <p>b. If so, and if it shows a yellow error page, how can we show a view of our own liking?</p>
  
  <p>2.If my view contains ajax calls, e.g. via jqgrid, and behind the scenes there are errors, I've noticed they also get picked up properly by Elmah. But how do I show some kind of an error message to the user as well?</p>
  
  <p>Thanks</p>