code: public static boolean causedBy( final Throwable                     ex,
                                      final Class<? extends Throwable>    exceptionClass )
      {
          Throwable    cause = ex;
  
          while( cause != null && ! exceptionClass.isInstance( cause ) )
          {
              cause = cause.getCause();
          }
  
          return ( cause == null ) ? false : true;
      }
docs: Checks to see if this exception or any of its causes
  is an instance of the given throwable class
  
  @param ex exception to check
  @param exceptionClass class of the exception
  
  @return true if it is