Class ExceptionTools
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.tools.ExceptionTools
-
public class ExceptionTools extends java.lang.ObjectContains common helper methods for dealing with exceptions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExceptionTools.DefaultErrorDebugInfoHandlerstatic classExceptionTools.ErrorDebugInfostatic interfaceExceptionTools.ErrorDebugInfoHandler
-
Constructor Summary
Constructors Constructor Description ExceptionTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseWithWarnings(java.lang.AutoCloseable closeable)Closes the specified closeable object.static FriendlyExceptiondecodeException(java.io.DataInput input)Decode an exception from an input streamstatic voidencodeException(java.io.DataOutput output, FriendlyException exception)Encode an exception to an output streamstatic <T extends java.lang.Throwable>
TfindDeepException(java.lang.Throwable throwable, java.lang.Class<T> klass)Finds the first exception which is an instance of the specified class from the throwable cause chain.static voidkeepInterrupted(java.lang.Throwable throwable)Makes sure thread is set to interrupted state when the throwable is an InterruptedExceptionstatic voidlog(org.slf4j.Logger log, FriendlyException exception, java.lang.Object context)Log a FriendlyException appropriately according to its severity.static voidrethrowErrors(java.lang.Throwable throwable)Sometimes it is necessary to catch Throwable instances for logging or reporting purposes.static voidsetDebugInfoHandler(ExceptionTools.ErrorDebugInfoHandler debugInfoHandler)static java.lang.RuntimeExceptionthrowWithDebugInfo(org.slf4j.Logger log, java.lang.Throwable cause, java.lang.String message, java.lang.String name, java.lang.String value)static java.lang.RuntimeExceptiontoRuntimeException(java.lang.Exception e)static FriendlyExceptionwrapUnfriendlyExceptions(java.lang.String message, FriendlyException.Severity severity, java.lang.Throwable throwable)If the exception is not a FriendlyException, wrap with a FriendlyException with the given messagestatic java.lang.RuntimeExceptionwrapUnfriendlyExceptions(java.lang.Throwable throwable)If the exception is not a FriendlyException, wrap with a RuntimeException
-
-
-
Method Detail
-
rethrowErrors
public static void rethrowErrors(java.lang.Throwable throwable)
Sometimes it is necessary to catch Throwable instances for logging or reporting purposes. However, unless for specific known cases, Error instances should not be blocked from propagating, so rethrow them.- Parameters:
throwable- The Throwable to check, it is rethrown if it is an Error
-
wrapUnfriendlyExceptions
public static FriendlyException wrapUnfriendlyExceptions(java.lang.String message, FriendlyException.Severity severity, java.lang.Throwable throwable)
If the exception is not a FriendlyException, wrap with a FriendlyException with the given message- Parameters:
message- Message of the new FriendlyException if neededseverity- Severity of the new FriendlyExceptionthrowable- The exception to potentially wrap- Returns:
- Original or wrapped exception
-
wrapUnfriendlyExceptions
public static java.lang.RuntimeException wrapUnfriendlyExceptions(java.lang.Throwable throwable)
If the exception is not a FriendlyException, wrap with a RuntimeException- Parameters:
throwable- The exception to potentially wrap- Returns:
- Original or wrapped exception
-
toRuntimeException
public static java.lang.RuntimeException toRuntimeException(java.lang.Exception e)
-
findDeepException
public static <T extends java.lang.Throwable> T findDeepException(java.lang.Throwable throwable, java.lang.Class<T> klass)Finds the first exception which is an instance of the specified class from the throwable cause chain.- Type Parameters:
T- The throwable class to scan for.- Parameters:
throwable- Throwable to scan.klass- The throwable class to scan for.- Returns:
- The first exception in the cause chain (including itself) which is an instance of the specified class.
-
keepInterrupted
public static void keepInterrupted(java.lang.Throwable throwable)
Makes sure thread is set to interrupted state when the throwable is an InterruptedException- Parameters:
throwable- Throwable to check
-
log
public static void log(org.slf4j.Logger log, FriendlyException exception, java.lang.Object context)Log a FriendlyException appropriately according to its severity.- Parameters:
log- Logger instance to log it toexception- The exception itselfcontext- An object that is included in the log
-
setDebugInfoHandler
public static void setDebugInfoHandler(ExceptionTools.ErrorDebugInfoHandler debugInfoHandler)
-
throwWithDebugInfo
public static java.lang.RuntimeException throwWithDebugInfo(org.slf4j.Logger log, java.lang.Throwable cause, java.lang.String message, java.lang.String name, java.lang.String value)
-
encodeException
public static void encodeException(java.io.DataOutput output, FriendlyException exception) throws java.io.IOExceptionEncode an exception to an output stream- Parameters:
output- Data outputexception- Exception to encode- Throws:
java.io.IOException- On IO error
-
closeWithWarnings
public static void closeWithWarnings(java.lang.AutoCloseable closeable)
Closes the specified closeable object. In case that throws an error, logs the error with WARN level, but does not rethrow.- Parameters:
closeable- Object to close.
-
decodeException
public static FriendlyException decodeException(java.io.DataInput input) throws java.io.IOException
Decode an exception from an input stream- Parameters:
input- Data input- Returns:
- Decoded exception
- Throws:
java.io.IOException- On IO error
-
-