public final class Exceptions extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T extends Throwable> |
clearTrace(T exception)
Empties the stack trace of the specified
exception. |
static boolean |
isExpected(Throwable cause)
Returns
true if the specified exception is expected to occur in well-known circumstances. |
static boolean |
isStreamCancelling(Throwable cause)
Returns
true if the specified exception will cancel the current request or response stream. |
static void |
logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
SessionProtocol protocol,
String debugData,
Throwable cause)
Logs the specified exception if it is unexpected.
|
static void |
logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
SessionProtocol protocol,
Throwable cause)
Logs the specified exception if it is unexpected.
|
static void |
logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
String debugData,
Throwable cause)
Logs the specified exception if it is unexpected.
|
static void |
logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
Throwable cause)
Logs the specified exception if it is unexpected.
|
static Throwable |
peel(Throwable throwable)
Returns the cause of the specified
throwable peeling it recursively, if it is one of the
CompletionException, ExecutionException, InvocationTargetException
or ExceptionInInitializerError. |
static <T> T |
throwUnsafely(Throwable cause)
Throws the specified exception violating the
throws clause of the enclosing method. |
static String |
traceText(Throwable exception)
Converts the stack trace of the specified
exception into a String. |
public static void logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
Throwable cause)
public static void logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
String debugData,
Throwable cause)
public static void logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
@Nullable
SessionProtocol protocol,
Throwable cause)
public static void logIfUnexpected(org.slf4j.Logger logger,
io.netty.channel.Channel ch,
@Nullable
SessionProtocol protocol,
String debugData,
Throwable cause)
public static boolean isExpected(Throwable cause)
true if the specified exception is expected to occur in well-known circumstances.
ClosedChannelExceptionClosedSessionExceptionIOException - 'Connection reset/closed/aborted by peer'Http2Exception - 'Stream closed'SSLException - 'SSLEngine closed already'Flags.verboseSocketExceptions()public static boolean isStreamCancelling(Throwable cause)
true if the specified exception will cancel the current request or response stream.public static <T extends Throwable> T clearTrace(T exception)
exception.public static <T> T throwUnsafely(Throwable cause)
throws clause of the enclosing method.
This method is useful when you need to rethrow a checked exception in Function, Consumer,
Supplier and Runnable, only if you are sure that the rethrown exception will be handled
as a Throwable or an Exception. For example:
CompletableFuture.supplyAsync(() -> {
try (FileInputStream fin = new FileInputStream(...)) {
....
return someValue;
} catch (IOException e) {
// 'throw e;' won't work because Runnable.run() does not allow any checked exceptions.
return Exceptions.throwUnsafely(e);
}
}).exceptionally(CompletionActions::log);
return Exceptions.throwUnsafely(...); vs.
Exceptions.throwUnsafely(...); return null;public static Throwable peel(Throwable throwable)
throwable peeling it recursively, if it is one of the
CompletionException, ExecutionException, InvocationTargetException
or ExceptionInInitializerError.
Otherwise returns the throwable.public static String traceText(Throwable exception)
exception into a String.
This method always uses '\n' as a line delimiter, unlike
Throwable.printStackTrace(PrintWriter) or Throwables#getStackTraceAsString(Throwable).Copyright © 2020 LeanCloud. All rights reserved.