title: Capturing parameters of a method at runtime in Java
body: <p>Our application uses several back-end services and we maintain wrappers which contain the methods to make the actual service calls. If any exception occurs in any of those methods while invoking a service, we throw a custom exception encapsulating the original exception as shown below.</p>
  
  <pre><code>interface IServiceA {
   public void submit(String user, String attributes);
  }
  
  public class ServiceAWrapper implements IserviceA {
   private ActualService getActualService() {
    .....
   }
  
   public void submit(String user, String attributes) {
    try {
     Request request = new Request();
     request.setUser(user);
     request.setAttributes(attributes);
     getActualService().call(request);
    } catch(ServiceException1 e) {
     throw new MyException(e, reason1);
    } catch(ServiceException2 e) {
     throw new MyException(e, reason2);
    }
   }
  }
  </code></pre>
  
  <p>I would like to know if there's any framework that would allow me to</p>
  
  <ol>
  <li>capture (and probably log) all the
  parameters passed to my wrapper
  methods at run-time; if the methods
  are called.</li>
  <li>capture the actual exception
  object(MyException instance in above
  example), if any thrown; so that I
  could append the passed parameters
  to the object at run-time.</li>
  </ol>
  
  <p>I am currently exploring AspectJ to see if it can address my requirements, but I am not sure if it can be used to capture the parameters passed to methods at runtime and also to capture exception objects, if any occur.</p>
  
  <p>Thanks.</p>