I have created a custom atttribute class like this
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class AMemento : Attribute
{
public void method(){
try {
}
catch (Exception) {
}}
}
and I am planning to use this custom attribute in a handler to catch any exceptions occur their as follows
[AMemento]
[Authorize]
public JsonResult GetWeatherData()
{
//// code here which throw an exception
}
I want to know the way to complete the custom attribute class to capture an exception thrown in GetWeatherData() handler. Is it possible to implement like a higher order function like in python ?
Within the MVC framework there is the HandleErrorAttribute class. This you can extend and override the OnException method. A good example of this is the in the Elmah MVC project where they have a HandleErrorAttribute class.
This question also provides some example of HandleErrorAttribute, again in the context of ELMAH but it should be relatively obvious that in overriding OnException you can provide your custom exception logic for MVC actions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With