tags:

views:

162

answers:

1

Created a simple class to test out the OnExceptionAspect in PostSharp.

[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public class ExceptionSwallower : OnExceptionAspect
{
    public override void OnException(MethodExecutionEventArgs eventArgs)
    {
        eventArgs.FlowBehavior = FlowBehavior.Return; 
        base.OnException(eventArgs);  
    }
}

Added the attribute to a method

    [ExceptionSwallower]
    public void SomeMethod()
    {
        throw new Exception();
    }

and invoked it.

However, the exception is not actually swallowed, which seems odd.

I haven't been able to find any similar problems, so I expect there is some minor thing I haven't gotten right. Anyone?

A: 

Sometimes it helps to look at the resulting assembly using Reflector. PostSharp generates plain .NET assemblies, there is no magic.

Gael Fraiteur