Using an interceptor for logging and exception handling
Interceptors are good for removing extraneous code from a method. In the
format method developed in the Using logging within an EJB recipe, most of the code was concerned with handling exceptions. This recipe shows how an interceptor can be used to greatly simplify the
The general process of using an interceptor for logging includes:
- Accessing the parameters of the target method
- Using the validation methods to validate the parameters
- Catching and logging any thrown exceptions
We will also need to modify the target class to accommodate the use of an interceptor.
The process of creating and using an interceptor class is detailed in Chapter 8, Interceptors. Here, we will ...