public final class Exceptions
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Exceptions.InterruptibleCall<ExceptionT extends java.lang.Exception,ResultT> |
static interface |
Exceptions.InterruptibleRun<ExceptionT extends java.lang.Exception> |
| Constructor and Description |
|---|
Exceptions() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkArgument(boolean validCondition,
java.lang.String argName,
java.lang.String message,
java.lang.Object... args)
Throws an IllegalArgumentException if the validCondition argument is false.
|
static void |
checkArrayRange(long startIndex,
int length,
long arrayLength,
java.lang.String startIndexArgName,
java.lang.String lengthArgName)
Throws an appropriate exception if the given range is not included in the given array interval.
|
static void |
checkNotClosed(boolean closed,
java.lang.Object targetObject)
Throws an ObjectClosedException if the closed argument is true.
|
static <K,V> java.util.Map<K,V> |
checkNotNullOrEmpty(java.util.Map<K,V> arg,
java.lang.String argName)
Throws a NullPointerException if the arg argument is null.
|
static java.lang.String |
checkNotNullOrEmpty(java.lang.String arg,
java.lang.String argName)
Throws a NullPointerException if the arg argument is null.
|
static <T,V extends java.util.Collection<T>> |
checkNotNullOrEmpty(V arg,
java.lang.String argName)
Throws a NullPointerException if the arg argument is null.
|
static <ExceptionT extends java.lang.Exception,ResultT> |
handleInterrupted(Exceptions.InterruptibleCall<ExceptionT,ResultT> call)
Eliminates boilerplate code of catching and re-interrupting the thread.
|
static <ExceptionT extends java.lang.Exception> |
handleInterrupted(Exceptions.InterruptibleRun<ExceptionT> run)
Eliminates boilerplate code of catching and re-interrupting the thread.
|
static boolean |
mustRethrow(java.lang.Throwable ex)
Determines if the given Throwable represents a fatal exception and cannot be handled.
|
static boolean |
shouldUnwrap(java.lang.Class<? extends java.lang.Exception> c)
Returns true if the provided class is CompletionException or ExecutionException which need to be unwrapped.
|
static java.lang.Throwable |
unwrap(java.lang.Throwable ex)
If the provided exception is a CompletionException or ExecutionException which need be unwrapped.
|
public static boolean mustRethrow(java.lang.Throwable ex)
ex - The Throwable to inspect.public static java.lang.Throwable unwrap(java.lang.Throwable ex)
ex - The exception to be unwrapped.public static boolean shouldUnwrap(java.lang.Class<? extends java.lang.Exception> c)
c - The class to be testedunwrap(Throwable) should be called on exceptions of this typepublic static <ExceptionT extends java.lang.Exception> void handleInterrupted(Exceptions.InterruptibleRun<ExceptionT> run) throws ExceptionT extends java.lang.Exception
NOTE: This method currently has the limitation that it can only handle functions that throw up to one additional
exception besides InterruptedException. This is a limitation of the Compiler.
ExceptionT - The type of exception.run - A method that should be run handling interrupts automaticallyExceptionT - If thrown by run.ExceptionT extends java.lang.Exceptionpublic static <ExceptionT extends java.lang.Exception,ResultT> ResultT handleInterrupted(Exceptions.InterruptibleCall<ExceptionT,ResultT> call) throws ExceptionT extends java.lang.Exception
NOTE: This method currently has the limitation that it can only handle functions that throw up to one additional
exception besides InterruptedException. This is a limitation of the Compiler.
ExceptionT - The type of exception.ResultT - The type of the result.call - A method that should be run handling interrupts automaticallyExceptionT - If thrown by call.ExceptionT extends java.lang.Exceptionpublic static java.lang.String checkNotNullOrEmpty(java.lang.String arg,
java.lang.String argName)
throws java.lang.NullPointerException,
java.lang.IllegalArgumentException
arg - The argument to check.argName - The name of the argument (to be included in the exception message).java.lang.NullPointerException - If arg is null.java.lang.IllegalArgumentException - If arg is not null, but has a length of zero.public static <T,V extends java.util.Collection<T>> V checkNotNullOrEmpty(V arg,
java.lang.String argName)
throws java.lang.NullPointerException,
java.lang.IllegalArgumentException
T - The type of elements in the provided collection.V - The actual type of the collection.arg - The argument to check.argName - The name of the argument (to be included in the exception message).java.lang.NullPointerException - If arg is null.java.lang.IllegalArgumentException - If arg is not null, but has a length of zero.public static <K,V> java.util.Map<K,V> checkNotNullOrEmpty(java.util.Map<K,V> arg,
java.lang.String argName)
throws java.lang.NullPointerException,
java.lang.IllegalArgumentException
K - The type of keys in the provided map.V - The type of keys in the provided map.arg - The argument to check.argName - The name of the argument (to be included in the exception message).java.lang.NullPointerException - If arg is null.java.lang.IllegalArgumentException - If arg is not null, but has a length of zero.public static void checkArgument(boolean validCondition,
java.lang.String argName,
java.lang.String message,
java.lang.Object... args)
throws java.lang.IllegalArgumentException
validCondition - The result of the condition to validate.argName - The name of the argument (to be included in the exception message).message - The message to include in the exception. This should not include the name of the argument,
as that is already prefixed.args - Format args for message. These must correspond to String.format() args.java.lang.IllegalArgumentException - If validCondition is false.public static void checkArrayRange(long startIndex,
int length,
long arrayLength,
java.lang.String startIndexArgName,
java.lang.String lengthArgName)
throws java.lang.ArrayIndexOutOfBoundsException,
java.lang.IllegalArgumentException
startIndex - The First index in the range.length - The number of items in the range.arrayLength - The length of the array.startIndexArgName - The name of the start index argument.lengthArgName - The name of the length argument.java.lang.ArrayIndexOutOfBoundsException - If startIndex is less than lowBoundInclusive or if startIndex+length is
greater than upBoundExclusive.java.lang.IllegalArgumentException - If length is a negative number.public static void checkNotClosed(boolean closed,
java.lang.Object targetObject)
throws ObjectClosedException
closed - The result of the condition to check. True if object is closed, false otherwise.targetObject - The object itself.ObjectClosedException - If closed is true.