spring.net aop advice
庚武讲堂 2010-08-13 02:25:21 请问,为一方法增加 IThrowsAdvice,在之方法里抛出异常,在vs中就抛出了,如何不让它抛出呢,而是在程序中打印出异常信息。
spring.net aop中的example是没有在vs中抛出的。差不多一样的代码,是不是vs哪里有设置?
public class ServiceCommand : ICommand
{
#region ICommand Members
public bool IsUndoCapable
{
get { return true; }
}
public void Execute()
{
Console.Out.WriteLine("---原生方法执行 ServiceCommand implementation : Execute()... ---");
throw new Exception("my exception");
}
public void UnExecute()
{
Console.Out.WriteLine("--- ServiceCommand implementation : UnExecute()... ---");
// Uncomment to see IThrowAdvice implementation in action
//throw new Exception("The method or operation is not supported.");
}
#endregion
}
/****************************************************/
static void Main(string[] args)
{
try
{
// Create AOP proxy programmatically.
ProxyFactory factory = new ProxyFactory(new ServiceCommand());
//factory.AddAdvice(new ConsoleLoggingBeforeAdvice());
//factory.AddAdvice(new ConsoleLoggingAfterAdvice());
//factory.AddAdvice(new ConsoleLoggingAroundAdvice());
factory.AddAdvice(new ConsoleLoggingThrowsAdvice());
ICommand command = (ICommand)factory.GetProxy();
command.Execute(); // //在此处就提示异常了,如何禁用?这里不是有捕获,可是还是出来了。
//if (command.IsUndoCapable)
//{
// command.UnExecute();
//}
}
catch (Exception ex)
{
Console.Out.WriteLine();
Console.Out.WriteLine(ex);
}
finally
{
Console.Out.WriteLine();
Console.WriteLine("done");
Console.Out.WriteLine("--- hit <return> to quit ---");
Console.ReadLine();
}
}