Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

ExceptionHandlerAdvice Class

Exception advice to perform exception translation, conversion of exceptions to default return values, and exception swallowing. Configuration is via a DSL like string for ease of use in common cases as well as allowing for custom translation logic by leveraging the Spring expression language.

For a list of all members of this type, see ExceptionHandlerAdvice Members .

System.Object
   AbstractExceptionHandlerAdvice
      ExceptionHandlerAdvice

[Visual Basic]
<Serializable> _
Public Class ExceptionHandlerAdvice
    Inherits AbstractExceptionHandlerAdvice
[C#]
[Serializable]
public class ExceptionHandlerAdvice : AbstractExceptionHandlerAdvice

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

The exception handler collection can be filled with either instances of objects that implement the interface IExceptionHandler or a string that follows a simple syntax for most common exception management needs. The source exceptions to perform processing on are listed immediately after the keyword 'on' and can be comma delmited. Following that is the action to perform, either log, translate, wrap, replace, return, or swallow. Following the action is a Spring expression language (SpEL) fragment that is used to either create the translated/wrapped/replaced exception or specify an alternative return value. The variables available to be used in the expression language fragment are, #method, #args, #target, and #e which are 1) the method that threw the exception, the arguments to the method, the target object itself, and the exception that was thrown. Using SpEL gives you great flexibility in creating a translation of an exception that has access to the calling context.

Common translation cases, wrap and rethrow, are supported with a shorter syntax where you can specify only the exception text for the new translated exception. If you ommit the exception text a default value will be used.

The exceptionsHandlers are compared to the thrown exception in the order they are listed. logging an exception will continue the evaluation process, in all other cases exceution stops at that point and the appropriate exceptions handler is executed.

  <property name="exceptionHandlers">
    <list>
      <value>on FooException1 log 'My Message, Method Name ' + #method.Name</value>
      <value>on FooException1 translate new BarException('My Message, Method Called = ' + #method.Name", #e)</value>
      <value>on FooException2,Foo3Exception wrap BarException 'My Bar Message'</value>
      <value>on FooException4 replace BarException 'My Bar Message'</value>
      <value>on FooException5 return 32</value>
      <value>on FooException6 swallow</value>
      <ref object="exceptionExpression" />
    </list>
  </property>

Requirements

Namespace: Spring.Aspects.Exceptions

Assembly: Spring.Aop (in Spring.Aop.dll)

See Also

ExceptionHandlerAdvice Members | Spring.Aspects.Exceptions Namespace