How to Show your Custom Exception from Action in MVC

Step 1: 
  1. public class HomeController : Controller  
  2.  {  
  3.         [HandleError()]  
  4.         public ActionResult Index()  
  5.         {  
  6.             throw new Exception("my exception");  
  7.         }  
  8. }  
Step 2: 
  1. <system.web>  
  2. <customErrors defaultRedirect="Error.cshtml" mode="On">  
  3. </customErrors>  
  4. </system.web>