本文整理汇总了Java中java.lang.Throwable类的典型用法代码示例。如果您正苦于以下问题:Java Throwable类的具体用法?Java Throwable怎么用?Java Throwable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Throwable类属于java.lang包,在下文中一共展示了Throwable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gcm_oneReadByteCorrupt
import java.lang.Throwable; //导入依赖的package包/类
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);
}
}
}
示例2: withLogging
import java.lang.Throwable; //导入依赖的package包/类
/**
* @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;
}
};
}
示例3: match
import java.lang.Throwable; //导入依赖的package包/类
@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);
}
示例4: map
import java.lang.Throwable; //导入依赖的package包/类
@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);
}
示例5: gcm_AEADBadTag
import java.lang.Throwable; //导入依赖的package包/类
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();
}
}
示例6: cbc_readAllIllegalBlockSize
import java.lang.Throwable; //导入依赖的package包/类
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);
}
}
}
示例7: onException
import java.lang.Throwable; //导入依赖的package包/类
/**
* @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;
}
};
}
示例8: withLogging
import java.lang.Throwable; //导入依赖的package包/类
/**
* @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;
}
};
}
示例9: thatReturnsOnCatch
import java.lang.Throwable; //导入依赖的package包/类
/**
* @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;
}
};
}
示例10: accept
import java.lang.Throwable; //导入依赖的package包/类
/**
* 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);
}
}
示例11: applyAsInt
import java.lang.Throwable; //导入依赖的package包/类
/**
* 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);
}
}
示例12: accept
import java.lang.Throwable; //导入依赖的package包/类
/**
* 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);
}
}
示例13: thatUnsafelyThrowsUnchecked
import java.lang.Throwable; //导入依赖的package包/类
/**
* @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);
}
};
}
示例14: get
import java.lang.Throwable; //导入依赖的package包/类
/**
* 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);
}
}
示例15: applyAsLong
import java.lang.Throwable; //导入依赖的package包/类
/**
* 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);
}
}