@SuppressWarnings("unchecked") public static <K extends Throwable>void rewrapAndThrowIfInstance(String newMessage,Throwable t,Class<K> clazz) throws K {
  if ((t != null) && clazz.isAssignableFrom(t.getClass())) {
    K kt=(K)t;
    K wrapped=Throwables.rewrap(newMessage,kt);
    throw wrapped;
  }
}

@ SuppressWarnings ( "unchecked" ) public static < K extends Throwable > void rewrapAndThrowIfInstance ( String newMessage , Throwable t , Class < K > clazz ) throws K { if ( ( t != null ) && clazz . isAssignableFrom ( t . getClass ( ) ) ) { K kt = ( K ) t ; K wrapped = Throwables . rewrap ( newMessage , kt ) ; throw wrapped ; } }
if ( t instanceof k ) throw throwables . rewrap ( ( k ) t ) ; < p > note : the runtime type of the thrown exception will be the same as t even if clazz is a supertype of t .
