Handle Error Attribute at ActionLevel
Description:
Controller:
[HandleError(ExceptionType = typeof(System.OverflowException), View = "overflowexception")]
public ActionResult overflowexception()
{
int value = int.MaxValue + int.Parse("1");
if (value < 0)
{
throw new OverflowException();
}
else
{
ViewBag.Result = value;
}
return View();
}
[HandleError(ExceptionType = typeof(System.OverflowException), View = "overflowexception")]
public ActionResult dividebyzeroexception()
{
int a = 10;
int b = 0;
int c = a / b;
return View();
}
[HandleError(ExceptionType = typeof(System.OverflowException), View = "overflowexception")]
public ActionResult overflowexception1()
{
int value = int.MaxValue + int.Parse("1");
if (value < 0)
{
throw new OverflowException();
}
else
{
ViewBag.Result = value;
}
return View();
}
------------------------------------------------------------------------------------------------------------
View:
overflowexception.cshtml:
@{
ViewBag.Title = "overflowexception";
}
<h2>overflowexception</h2>
<h2>@ViewBag.Result</h2>
-------------------------------------------------------------------------------------------------------------
ScreenShot:
Execution path:/Home/overflowexception
Throw the error Overflowexception and Display the overflowexception view.

UI:

Execution path:Home/dividebyzeroexception
Error occur as Dividebyzeroexception and not display the overflowexception view.Because,specify the handle error for overflowexception only.

UI:

Execution path:/Home/overflowexception1

UI:

-----------------------------------------------------------------------------------------------------------
Conclusion:
Created the new page for display the overflowexception .
Description:
- Here,Used the handleerrorattribute at action level.
- ExceptionType property of HandleError: Catch the specify error at action level.
- View property of HandleError:Display the view page,If occur specify error of executiontypeproperty in Action level.
- Create view only for overflowexception
Controller:
[HandleError(ExceptionType = typeof(System.OverflowException), View = "overflowexception")]
public ActionResult overflowexception()
{
int value = int.MaxValue + int.Parse("1");
if (value < 0)
{
throw new OverflowException();
}
else
{
ViewBag.Result = value;
}
return View();
}
[HandleError(ExceptionType = typeof(System.OverflowException), View = "overflowexception")]
public ActionResult dividebyzeroexception()
{
int a = 10;
int b = 0;
int c = a / b;
return View();
}
[HandleError(ExceptionType = typeof(System.OverflowException), View = "overflowexception")]
public ActionResult overflowexception1()
{
int value = int.MaxValue + int.Parse("1");
if (value < 0)
{
throw new OverflowException();
}
else
{
ViewBag.Result = value;
}
return View();
}
------------------------------------------------------------------------------------------------------------
View:
overflowexception.cshtml:
@{
ViewBag.Title = "overflowexception";
}
<h2>overflowexception</h2>
<h2>@ViewBag.Result</h2>
-------------------------------------------------------------------------------------------------------------
ScreenShot:
Execution path:/Home/overflowexception
Throw the error Overflowexception and Display the overflowexception view.
UI:
Execution path:Home/dividebyzeroexception
Error occur as Dividebyzeroexception and not display the overflowexception view.Because,specify the handle error for overflowexception only.
UI:
Execution path:/Home/overflowexception1
UI:
-----------------------------------------------------------------------------------------------------------
Conclusion:
Created the new page for display the overflowexception .