Handle Error Attribute at Global Level

Monday, 17 February 2014

Handle Error Attribute at Global Level


Controller:

   public class GlobalOverflowExceptionController : Controller
    {
        //
        // GET: /GlobalOverflowException/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult overflowexception()
        {

            int value = int.MaxValue + int.Parse("1");

            if (value < 0)
            {
                throw new OverflowException();

            }
            else
            {
                ViewBag.Result = value;
            }
            return View();
        }

        public ActionResult dividebyzeroexception()
        {


            int a = 10;
            int b = 0;
            int c = a / b;
            return View();
        }

        public ActionResult overflowexception1()
        {

            int value = int.MaxValue + int.Parse("1");

            if (value < 0)
            {
                throw new OverflowException();

            }
            else
            {
                ViewBag.Result = value;
            }
            return View();
        }

    }

HandleError Attribute at Global Level:

 

 

 

View:

overflowexception:

@{
    ViewBag.Title = "overflowexception";
}

<h2>overflowexception</h2>
<h2>@ViewBag.Result</h2>

 

Screenshot:

 

 

 

Comment overflowexception filter 

 

 Screenshot:

 

 

 Conclusion:

     Catch the overflowexception at application level.