I have an aspect that writes something to the console on exception.
I have a base class that throws an exception on its constructor, and a derived class that have the aspect on its constructor.
I would expect that the derived class aspect on constructor will catch the base class exception, but it dont.
Is this by design? Is this a bug?
Or am I doing something wrong?
Here is sample code (Console Application):
[Serializable]
public class OnExceptionWriteAspect : OnMethodBoundaryAspect
{
public override void OnException(MethodExecutionEventArgs eventArgs)
{
Console.WriteLine("Exception catched on Aspect.");
}
}
public class BaseClass
{
public BaseClass()
{
throw new Exception();
}
}
public class DerivedClass : BaseClass
{
[OnExceptionWriteAspect]
public DerivedClass()
: base()
{
}
}
public class Program
{
static void Main(string[] args)
{
try
{
new DerivedClass();
}
catch
{
Console.WriteLine("Exception catched on Main.");
}
}
}
The output is:
Exception catched on Main.
This is by design. There is no way to put an exception handler around the call to the base constructor. The MSIL code would not be verifiable.