public <T extends Exception> ExceptionHandler throwIfInstance(Class<T> t) throws T {
    if (t.isInstance(e)) {
      throw t.cast(e);
    }
    return this;
  }
@Test
  public void testThrowIfInstance() {

    MetaException me = new MetaException("MetaException test");
    try {
      handleException(me).throwIfInstance(RuntimeException.class);
    } catch (Exception e) {
      fail("Exception should not happen:" + e.getMessage());
    }

    try {
      handleException(me).throwIfInstance(MetaException.class);
      fail("Should throw a exception here");
    } catch (Exception e) {
      assertTrue(e == me);
    }

    InvalidOperationException ioe = new InvalidOperationException("InvalidOperationException test");
    try {
      handleException(ioe).throwIfInstance(MetaException.class, InvalidOperationException.class);
      fail("Should throw a exception here");
    } catch (Exception e) {
      assertTrue(e == ioe);
    }

    TException te = new TException("TException");
    try {
      handleException(te).throwIfInstance(MetaException.class, InvalidOperationException.class)
          .throwIfInstance(TException.class).defaultMetaException();
    } catch (Exception e) {
      assertTrue(e == te);
    }

    RuntimeException re = new RuntimeException("RuntimeException test");
    try {
      Exception e = handleException(re).throwIfInstance(MetaException.class, InvalidOperationException.class)
          .throwIfInstance(TException.class).defaultRuntimeException();
      assertTrue(e == re);
    } catch (Exception e) {
      fail("Exception should not happen:" + e.getMessage());
    }

    NullPointerException npe = new NullPointerException();
    try {
      Exception e = handleException(npe).throwIfInstance(MetaException.class, InvalidOperationException.class)
          .throwIfInstance(TException.class).defaultMetaException();
      assertTrue(e instanceof MetaException);
      assertTrue(e.getMessage().equals(npe.toString()));
    } catch (Exception e) {
      fail("Exception should not happen:" + e.getMessage());
    }

    try {
      handleException(me).throwIfInstance(MetaException.class, InvalidOperationException.class)
          .throwIfInstance(TException.class).defaultMetaException();
      fail("Should throw a exception here");
    } catch (Exception e) {
      assertTrue(e == me);
    }
  }