.net Attributes that handle exceptions - usage on a property accessor

Posted by Mr AH on Stack Overflow See other posts from Stack Overflow or by Mr AH
Published on 2010-04-03T13:39:04Z Indexed on 2010/04/03 13:43 UTC
Read the original article Hit count: 250

Hi, well I know from my asp.net mvc experience that you can have attributes that handle exceptions (HandleErrorAttribute). As far as I can tell the Controller class has some OnException event which may be integral to this behaviour. However, I want to do something similar in my own code:

dream example:

public String MyProperty
{
    [ExceptionBehaviour(typeof(FormatException), MyExEnum.ClearValue)]
    set
    {
        _thing.prop = Convert.ToThing(value);
    }
}
....

The code above obviously makes very little sense, but is close to the kind of thing I wish to do. I want the attribute on the property set accessor to catch some type of exception and then deal with this in some custom way (or even just swallow it).

Any ideas guys?

© Stack Overflow or respective owner

Related posts about exception-handling

Related posts about custom-attributes