Class TrapException

java.lang.Object
org.apache.tomcat.jdbc.pool.JdbcInterceptor
org.apache.tomcat.jdbc.pool.TrapException
All Implemented Interfaces:
InvocationHandler

public class TrapException extends JdbcInterceptor
Interceptor that translates an exception type the invoked method does not declare into a type it does, so that a call through the pool's connection proxy respects the InvocationHandler contract: the exception is re-thrown unchanged when the method declares it (a subclass of a declared type passes as well), replaced by an SQLException carrying it as the cause when the method declares SQLException, and replaced by a RuntimeException carrying it as the cause otherwise. An Error is always re-thrown as it is, including one carried by an InvocationTargetException.

The pool prepends this interceptor to the definitions parsed from jdbcInterceptors, so it heads the chain of every connection that has an interceptor chain at all; a pool configured without an interceptor list has no chain and therefore no trap. An undeclared checked exception reaching such an untrapped connection still respects the proxy contract - the JDK proxy itself turns it into an UndeclaredThrowableException - what the trap adds on top of that is the declared, JDBC-shaped exception with the original preserved as its cause.

  • Constructor Details

    • TrapException

      public TrapException()
      Constructs a new TrapException interceptor.
  • Method Details

    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Description copied from class: JdbcInterceptor
      Gets invoked each time an operation on Connection is invoked.

      The base implementation passes the call to the next interceptor in the chain. When there is no next interceptor, the call fails fast with a NullPointerException: a chain built by the pool always ends in the ProxyConnection terminal, so reaching this case means a chain was hand-built without a terminal link. Interceptors that do not answer a call themselves continue it with super.invoke(proxy, method, args).

      Specified by:
      invoke in interface InvocationHandler
      Overrides:
      invoke in class JdbcInterceptor
      Throws:
      Throwable
    • isDeclaredException

      public boolean isDeclaredException(Method m, Class<?> clazz)
      Checks if the given exception class is declared in the throws clause of the specified method.
      Parameters:
      m - The method to check
      clazz - The exception class to look for
      Returns:
      true if the exception is declared, false otherwise
    • reset

      public void reset(ConnectionPool parent, PooledConnection con)
      no-op for this interceptor. no state is stored.
      Specified by:
      reset in class JdbcInterceptor
      Parameters:
      parent - - the connection pool owning the connection
      con - - the pooled connection