Java 类java.lang.Throwable 实例源码

项目:jdk8u-jdk    文件:CipherInputStreamExceptions.java   
static void gcm_oneReadByteCorrupt() throws Exception {

        System.out.println("Running gcm_oneReadByteCorrupt test");

        // Encrypt 100 bytes with AES/GCM/PKCS5Padding
        byte[] ct = encryptedText("GCM", 100);
        // Corrupt the encrypted message
        ct = corruptGCM(ct);
        // Create stream for decryption
        CipherInputStream in = getStream("GCM", ct);

        try {
            in.read();
            System.out.println("  Fail. No exception thrown.");
        } catch (IOException e) {
            Throwable ec = e.getCause();
            if (ec instanceof AEADBadTagException) {
                System.out.println("  Pass.");
            } else {
                System.out.println("  Fail: " + ec.getMessage());
                throw new RuntimeException(ec);
            }
        }
    }
项目:openjdk-jdk10    文件:CipherInputStreamExceptions.java   
static void gcm_oneReadByteCorrupt() throws Exception {

        System.out.println("Running gcm_oneReadByteCorrupt test");

        // Encrypt 100 bytes with AES/GCM/PKCS5Padding
        byte[] ct = encryptedText("GCM", 100);
        // Corrupt the encrypted message
        ct = corruptGCM(ct);
        // Create stream for decryption
        CipherInputStream in = getStream("GCM", ct);

        try {
            in.read();
            System.out.println("  Fail. No exception thrown.");
        } catch (IOException e) {
            Throwable ec = e.getCause();
            if (ec instanceof AEADBadTagException) {
                System.out.println("  Pass.");
            } else {
                System.out.println("  Fail: " + ec.getMessage());
                throw new RuntimeException(ec);
            }
        }
    }
项目:throwable-interfaces    文件:ObjLongConsumerWithThrowable.java   
/**
 * @param logger The logger to log exceptions on
 * @param message A message to use for logging exceptions
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default ObjLongConsumerWithThrowable<T, E> withLogging(final Logger logger, final String message) {
    return (final T v1, final long v2) -> {
        try {
            acceptWithThrowable(v1, v2);
        } catch (final Throwable throwable) {
            logger.error(message, v1, v2, throwable);
            throw throwable;
        }
    };
}
项目:dataenum    文件:GenericValues.java   
@Override
public final void match(
    @Nonnull Consumer<Left<L>> left,
    @Nonnull Consumer<Right<Throwable>> right,
    @Nonnull Consumer<Neither> neither,
    @Nonnull Consumer<Both<L, Throwable>> both) {
  left.accept(this);
}
项目:dataenum    文件:GenericValues.java   
@Override
public final <R_> R_ map(
    @Nonnull Function<Left<L>, R_> left,
    @Nonnull Function<Right<Throwable>, R_> right,
    @Nonnull Function<Neither, R_> neither,
    @Nonnull Function<Both<L, Throwable>, R_> both) {
  return left.apply(this);
}
项目:dataenum    文件:GenericValues.java   
@Override
public final void match(
    @Nonnull Consumer<Left<Object>> left,
    @Nonnull Consumer<Right<Throwable>> right,
    @Nonnull Consumer<Neither> neither,
    @Nonnull Consumer<Both<Object, Throwable>> both) {
  neither.accept(this);
}
项目:dataenum    文件:GenericValues.java   
@Override
public final <R_> R_ map(
    @Nonnull Function<Left<Object>, R_> left,
    @Nonnull Function<Right<Throwable>, R_> right,
    @Nonnull Function<Neither, R_> neither,
    @Nonnull Function<Both<Object, Throwable>, R_> both) {
  return neither.apply(this);
}
项目:jdk8u-jdk    文件:CipherInputStreamExceptions.java   
static void gcm_AEADBadTag() throws Exception {
    Cipher c;
    byte[] read = new byte[200];

    System.out.println("Running gcm_AEADBadTag");

    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Corrupt the encrypted message
    ct = corruptGCM(ct);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);

    try {
        int size = in.read(read);
        throw new RuntimeException("Fail: CipherInputStream.read() " +
                "returned " + size + " and didn't throw an exception.");
    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof AEADBadTagException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    } finally {
        in.close();
    }
}
项目:jdk8u-jdk    文件:CipherInputStreamExceptions.java   
static void cbc_readAllIllegalBlockSize() throws Exception {
    byte[] read = new byte[200];

    System.out.println("Running cbc_readAllIllegalBlockSize test");

    // Encrypt 96 byte with AES/CBC/PKCS5Padding
    byte[] ct = encryptedText("CBC", 96);
    // Create a stream with only 95 bytes of encrypted data
    CipherInputStream in = getStream("CBC", ct, 95);

    try {
        int s, size = 0;
        while ((s = in.read(read)) != -1) {
            size += s;
        }
        throw new RuntimeException("Fail: No IllegalBlockSizeException. " +
                "CipherInputStream.read() returned " + size);

    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof IllegalBlockSizeException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    }
}
项目:openjdk-jdk10    文件:CipherInputStreamExceptions.java   
static void gcm_AEADBadTag() throws Exception {
    Cipher c;
    byte[] read = new byte[200];

    System.out.println("Running gcm_AEADBadTag");

    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Corrupt the encrypted message
    ct = corruptGCM(ct);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);

    try {
        int size = in.read(read);
        throw new RuntimeException("Fail: CipherInputStream.read() " +
                "returned " + size + " and didn't throw an exception.");
    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof AEADBadTagException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    } finally {
        in.close();
    }
}
项目:openjdk-jdk10    文件:CipherInputStreamExceptions.java   
static void cbc_readAllIllegalBlockSize() throws Exception {
    byte[] read = new byte[200];

    System.out.println("Running cbc_readAllIllegalBlockSize test");

    // Encrypt 96 byte with AES/CBC/PKCS5Padding
    byte[] ct = encryptedText("CBC", 96);
    // Create a stream with only 95 bytes of encrypted data
    CipherInputStream in = getStream("CBC", ct, 95);

    try {
        int s, size = 0;
        while ((s = in.read(read)) != -1) {
            size += s;
        }
        throw new RuntimeException("Fail: No IllegalBlockSizeException. " +
                "CipherInputStream.read() returned " + size);

    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof IllegalBlockSizeException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    }
}
项目:throwable-interfaces    文件:DoubleToIntFunctionWithThrowable.java   
/**
 * @param consumer An exception consumer.
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default DoubleToIntFunctionWithThrowable<E> onException(final Consumer<Throwable> consumer) {
    return (final double v1) -> {
        try {
            return applyAsIntWithThrowable(v1);
        } catch (final Throwable throwable) {
            consumer.accept(throwable);
            throw throwable;
        }
    };
}
项目:openjdk9    文件:CipherInputStreamExceptions.java   
static void gcm_AEADBadTag() throws Exception {
    Cipher c;
    byte[] read = new byte[200];

    System.out.println("Running gcm_AEADBadTag");

    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Corrupt the encrypted message
    ct = corruptGCM(ct);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);

    try {
        int size = in.read(read);
        throw new RuntimeException("Fail: CipherInputStream.read() " +
                "returned " + size + " and didn't throw an exception.");
    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof AEADBadTagException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    } finally {
        in.close();
    }
}
项目:throwable-interfaces    文件:DoublePredicateWithThrowable.java   
/**
 * @param logger The logger to log exceptions on
 * @param message A message to use for logging exceptions
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default DoublePredicateWithThrowable<E> withLogging(final Logger logger, final String message) {
    return (final double v1) -> {
        try {
            return testWithThrowable(v1);
        } catch (final Throwable throwable) {
            logger.error(message, v1, throwable);
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:LongToIntFunctionWithThrowable.java   
/**
 * @param defaultReturnValue A value to return if any throwable is caught.
 * @return An interface that returns a default value if any exception occurs.
 */
default LongToIntFunction thatReturnsOnCatch(final int defaultReturnValue) {
  return (final long v1) -> {
    try {
      return applyAsIntWithThrowable(v1);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}
项目:throwable-interfaces    文件:ObjLongConsumerWithThrowable.java   
/**
 * Overridden method of ObjLongConsumerWithThrowable that will call acceptWithThrowable, but catching any exceptions.
 *
 * @param v1 parameter to overridden method
 * @param v2 parameter to overridden method
 */
@Override
default void accept(final T v1, final long v2) {
    try {
        acceptWithThrowable(v1, v2);
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:jdk8u_jdk    文件:CipherInputStreamExceptions.java   
static void cbc_readAllIllegalBlockSize() throws Exception {
    byte[] read = new byte[200];

    System.out.println("Running cbc_readAllIllegalBlockSize test");

    // Encrypt 96 byte with AES/CBC/PKCS5Padding
    byte[] ct = encryptedText("CBC", 96);
    // Create a stream with only 95 bytes of encrypted data
    CipherInputStream in = getStream("CBC", ct, 95);

    try {
        int s, size = 0;
        while ((s = in.read(read)) != -1) {
            size += s;
        }
        throw new RuntimeException("Fail: No IllegalBlockSizeException. " +
                "CipherInputStream.read() returned " + size);

    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof IllegalBlockSizeException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    }
}
项目:throwable-interfaces    文件:LongToIntFunctionWithThrowable.java   
/**
 * Overridden method of LongToIntFunctionWithThrowable that will call applyAsIntWithThrowable, but catching any exceptions.
 *
 * @param v1 parameter to overridden method
 * @return the value
 */
@Override
default int applyAsInt(final long v1) {
    try {
        return applyAsIntWithThrowable(v1);
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:DoubleConsumerWithThrowable.java   
/**
 * Overridden method of DoubleConsumerWithThrowable that will call acceptWithThrowable, but catching any exceptions.
 *
 * @param v1 parameter to overridden method
 */
@Override
default void accept(final double v1) {
    try {
        acceptWithThrowable(v1);
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:LongConsumerWithThrowable.java   
/**
 * @throws E if an exception E has been thrown, it is rethrown by this method
 * @return An interface that is only returned if no exception has been thrown.
 */
default LongConsumer thatUnsafelyThrowsUnchecked() throws E {
    return (final long v1) -> {
        try {
            acceptWithThrowable(v1);
        } catch(final Throwable throwable) {
            SuppressedException.throwUnsafelyAsUnchecked(throwable);
        }
    };
}
项目:throwable-interfaces    文件:SupplierWithThrowable.java   
/**
 * Overridden method of SupplierWithThrowable that will call getWithThrowable, but catching any exceptions.
 *
 * @return the value
 */
@Override
default T get() {
    try {
        return getWithThrowable();
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:ToLongBiFunctionWithThrowable.java   
/**
 * Overridden method of ToLongBiFunctionWithThrowable that will call applyAsLongWithThrowable, but catching any exceptions.
 *
 * @param v1 parameter to overridden method
 * @param v2 parameter to overridden method
 * @return the value
 */
@Override
default long applyAsLong(final T v1, final U v2) {
    try {
        return applyAsLongWithThrowable(v1, v2);
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:DoublePredicateWithThrowable.java   
/**
 * @param consumer An exception consumer.
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default DoublePredicateWithThrowable<E> onException(final Consumer<Throwable> consumer) {
    return (final double v1) -> {
        try {
            return testWithThrowable(v1);
        } catch (final Throwable throwable) {
            consumer.accept(throwable);
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:ObjIntConsumerWithThrowable.java   
/**
 * Overridden method of ObjIntConsumerWithThrowable that will call acceptWithThrowable, but catching any exceptions.
 *
 * @param v1 parameter to overridden method
 * @param v2 parameter to overridden method
 */
@Override
default void accept(final T v1, final int v2) {
    try {
        acceptWithThrowable(v1, v2);
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:PredicateWithThrowable.java   
/**
 * Overridden method of PredicateWithThrowable that will call testWithThrowable, but catching any exceptions.
 *
 * @param v1 parameter to overridden method
 * @return the value
 */
@Override
default boolean test(final T v1) {
    try {
        return testWithThrowable(v1);
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:PredicateWithThrowable.java   
/**
 * @param defaultReturnValue A value to return if any throwable is caught.
 * @return An interface that returns a default value if any exception occurs.
 */
default Predicate<T> thatReturnsOnCatch(final boolean defaultReturnValue) {
  return (final T v1) -> {
    try {
      return testWithThrowable(v1);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}
项目:throwable-interfaces    文件:DoubleToLongFunctionWithThrowable.java   
/**
 * Overridden method of DoubleToLongFunctionWithThrowable that will call applyAsLongWithThrowable, but catching any exceptions.
 *
 * @param v1 parameter to overridden method
 * @return the value
 */
@Override
default long applyAsLong(final double v1) {
    try {
        return applyAsLongWithThrowable(v1);
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:PredicateWithThrowable.java   
/**
 * @param logger The logger to log exceptions on
 * @param message A message to use for logging exceptions
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default PredicateWithThrowable<T, E> withLogging(final Logger logger, final String message) {
    return (final T v1) -> {
        try {
            return testWithThrowable(v1);
        } catch (final Throwable throwable) {
            logger.error(message, v1, throwable);
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:PredicateWithThrowable.java   
/**
 * @param consumer An exception consumer.
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default PredicateWithThrowable<T, E> onException(final Consumer<Throwable> consumer) {
    return (final T v1) -> {
        try {
            return testWithThrowable(v1);
        } catch (final Throwable throwable) {
            consumer.accept(throwable);
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:ConsumerWithThrowable.java   
/**
 * @param consumer An exception consumer.
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default ConsumerWithThrowable<T, E> onException(final Consumer<Throwable> consumer) {
    return (final T v1) -> {
        try {
            acceptWithThrowable(v1);
        } catch (final Throwable throwable) {
            consumer.accept(throwable);
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:DoubleToIntFunctionWithThrowable.java   
/**
 * @param consumer An exception consumer.
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default DoubleToIntFunctionWithThrowable<E> onException(final java.util.function.BiConsumer<Throwable, Object[]> consumer) {
    return (final double v1) -> {
        try {
            return applyAsIntWithThrowable(v1);
        } catch (final Throwable throwable) {
            consumer.accept(throwable, new Object[]{v1});
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:LongBinaryOperatorWithThrowable.java   
/**
 * @param defaultReturnValue A value to return if any throwable is caught.
 * @return An interface that returns a default value if any exception occurs.
 */
default LongBinaryOperator thatReturnsOnCatch(final long defaultReturnValue) {
  return (final long v1, final long v2) -> {
    try {
      return applyAsLongWithThrowable(v1, v2);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}
项目:throwable-interfaces    文件:LongBinaryOperatorWithThrowable.java   
/**
 * @throws E if an exception E has been thrown, it is rethrown by this method
 * @return An interface that is only returned if no exception has been thrown.
 */
default LongBinaryOperator thatUnsafelyThrowsUnchecked() throws E {
  return (final long v1, final long v2) -> {
    try {
      return applyAsLongWithThrowable(v1, v2);
    } catch(final Throwable throwable) {
       SuppressedException.throwUnsafelyAsUnchecked(throwable);
       return 0;        }
  };
}
项目:throwable-interfaces    文件:ObjIntConsumerWithThrowable.java   
/**
 * @throws E if an exception E has been thrown, it is rethrown by this method
 * @return An interface that is only returned if no exception has been thrown.
 */
default ObjIntConsumer<T> thatUnsafelyThrowsUnchecked() throws E {
    return (final T v1, final int v2) -> {
        try {
            acceptWithThrowable(v1, v2);
        } catch(final Throwable throwable) {
            SuppressedException.throwUnsafelyAsUnchecked(throwable);
        }
    };
}
项目:throwable-interfaces    文件:IntFunctionWithThrowable.java   
/**
 * @return An interface that will wrap the result in an optional, and return an empty optional when an exception occurs.
 */
default IntFunction<java.util.Optional<R>>    thatReturnsOptional() {
  return (final int v1)     -> {
    try {
      return java.util.Optional.ofNullable(applyWithThrowable(v1));
    } catch(Throwable throwable) {
      return java.util.Optional.empty();
    }
  };
}
项目:throwable-interfaces    文件:ObjLongConsumerWithThrowable.java   
/**
 * @return An interface that completely ignores exceptions. Consider using this method withLogging() as well.
 */
default ObjLongConsumer<T> thatThrowsNothing() {
    return (final T v1, final long v2) -> {
        try {
            acceptWithThrowable(v1, v2);
        } catch(Throwable ignored) {}
    };
}
项目:throwable-interfaces    文件:LongSupplierWithThrowable.java   
/**
 * Overridden method of LongSupplierWithThrowable that will call getAsLongWithThrowable, but catching any exceptions.
 *
 * @return the value
 */
@Override
default long getAsLong() {
    try {
        return getAsLongWithThrowable();
    } catch (final RuntimeException | Error exception) {
        throw exception;
    } catch (final Throwable throwable) {
        throw new SuppressedException(throwable);
    }
}
项目:throwable-interfaces    文件:DoubleToIntFunctionWithThrowable.java   
/**
 * @param logger The logger to log exceptions on
 * @param message A message to use for logging exceptions
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default DoubleToIntFunctionWithThrowable<E> withLogging(final Logger logger, final String message) {
    return (final double v1) -> {
        try {
            return applyAsIntWithThrowable(v1);
        } catch (final Throwable throwable) {
            logger.error(message, v1, throwable);
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:IntPredicateWithThrowable.java   
/**
 * @param consumer An exception consumer.
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default IntPredicateWithThrowable<E> onException(final Consumer<Throwable> consumer) {
    return (final int v1) -> {
        try {
            return testWithThrowable(v1);
        } catch (final Throwable throwable) {
            consumer.accept(throwable);
            throw throwable;
        }
    };
}
项目:throwable-interfaces    文件:DoubleToLongFunctionWithThrowable.java   
/**
 * @param consumer An exception consumer.
 * @return An interface that will log all exceptions to given logger
 */
@SuppressWarnings("Duplicates")
default DoubleToLongFunctionWithThrowable<E> onException(final java.util.function.BiConsumer<Throwable, Object[]> consumer) {
    return (final double v1) -> {
        try {
            return applyAsLongWithThrowable(v1);
        } catch (final Throwable throwable) {
            consumer.accept(throwable, new Object[]{v1});
            throw throwable;
        }
    };
}