Class Throwables
java.lang.Object
be.imgn.gaia.core.base.Throwables
Creates exceptions from the exception that caused them.
The methods return the exception rather than throw it, so that the caller throws it: the compiler then knows that the code after it is not reached.
int port;
try {
port = Integer.parseInt(text);
} catch (NumberFormatException e) {
throw Throwables.illegalArgument(e, "Not a port: %s", text);
}
A message format follows the syntax of String.format(Locale, String, Object...) and is formatted in
Locale.ROOT, so that messages do not depend on the default locale.
- Since:
- 0.1.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic IllegalArgumentExceptionillegalArgument(Throwable cause, @Nullable Object message) Creates an exception that reports an illegal argument, caused by another exception.static IllegalArgumentExceptionillegalArgument(Throwable cause, String messageFormat, @Nullable Object... params) Creates an exception that reports an illegal argument, caused by another exception.static IllegalStateExceptionillegalState(Throwable cause, @Nullable Object message) Creates an exception that reports an illegal state, caused by another exception.static IllegalStateExceptionillegalState(Throwable cause, String messageFormat, @Nullable Object... params) Creates an exception that reports an illegal state, caused by another exception.
-
Method Details
-
illegalArgument
Creates an exception that reports an illegal argument, caused by another exception.- Parameters:
cause- the exception that caused itmessage- the message of the exception, converted withString.valueOf(Object)- Returns:
- a new exception, for the caller to throw
-
illegalArgument
@FormatMethod public static IllegalArgumentException illegalArgument(Throwable cause, @FormatString String messageFormat, @Nullable Object... params) Creates an exception that reports an illegal argument, caused by another exception.- Parameters:
cause- the exception that caused itmessageFormat- the format of the message of the exceptionparams- the values the format refers to- Returns:
- a new exception, for the caller to throw
- Throws:
IllegalFormatException- ifmessageFormatis not a valid format forparams
-
illegalState
Creates an exception that reports an illegal state, caused by another exception.- Parameters:
cause- the exception that caused itmessage- the message of the exception, converted withString.valueOf(Object)- Returns:
- a new exception, for the caller to throw
-
illegalState
@FormatMethod public static IllegalStateException illegalState(Throwable cause, @FormatString String messageFormat, @Nullable Object... params) Creates an exception that reports an illegal state, caused by another exception.- Parameters:
cause- the exception that caused itmessageFormat- the format of the message of the exceptionparams- the values the format refers to- Returns:
- a new exception, for the caller to throw
- Throws:
IllegalFormatException- ifmessageFormatis not a valid format forparams
-