Class ExceptionBuilder<T extends Exception>
java.lang.Object
io.github.chrimle.exceptionfactory.ExceptionBuilder<T>
- Type Parameters:
T-Exception-class instance to build and instantiate.
Builder of
Exceptions.- Since:
- 0.1.0
- Author:
- Chrimle
-
Method Summary
Modifier and TypeMethodDescriptionbuild()static <C extends Exception>
@NotNull ExceptionBuilder<C>Creates a newExceptionBuilderinstance for building and instantiating anExceptionof typeExceptionBuilder.Sets thecauseto be used when instantiatingExceptionBuilder,setMessage(@Nullable String message) Sets themessageto be used when instantiatingExceptionBuilder.setMessage(MessageTemplates.OneArgTemplate messageTemplate, String messageArg) Sets themessageto be used when instantiatingExceptionBuilder, by applying themessageArgto themessageTemplate.setMessage(MessageTemplates.TwoArgTemplate messageTemplate, String messageArgOne, String messageArgTwo) Sets themessageto be used when instantiatingExceptionBuilder, by applying themessageArgOneandmessageArgTwoto themessageTemplate.setMessage(String formattedString, String... messageArgs) Sets themessageto be used when instantiatingExceptionBuilder, by formattingformattedStringwith the format specifiersmessageArgs.setMessage(BiFunction<String, String, String> messageBuilder, @Nullable String messageArg1, @Nullable String messageArg2) Sets themessageto be used when instantiatingExceptionBuilder, by invokingmessageBuilderwithmessageArg1andmessageArg2.setMessage(UnaryOperator<String> messageBuilder, @Nullable String messageArg) Sets themessageto be used when instantiatingExceptionBuilder, by invokingmessageBuilderwithmessageArg.
-
Method Details
-
of
@Contract("null -> fail; _ -> new") @NotNull public static <C extends Exception> @NotNull ExceptionBuilder<C> of(Class<C> exceptionClass) Creates a newExceptionBuilderinstance for building and instantiating anExceptionof typeExceptionBuilder.- Type Parameters:
C- to build and instantiate.- Parameters:
exceptionClass- to build and instantiate.- Returns:
- a new
ExceptionBuilderinstance. - Throws:
IllegalArgumentException- ifexceptionClassisnull.exceptionClassMUST NOT benull.IllegalArgumentException- ifexceptionClassdoes not have a constructor with method argumentsExampleException(String, Throwable).exceptionClassMUST have a(String, Throwable)constructor.- Since:
- 0.1.0
-
setMessage
@Contract(value="_ -> this", mutates="this") public ExceptionBuilder<T> setMessage(@Nullable @Nullable String message) Sets themessageto be used when instantiatingExceptionBuilder.- Parameters:
message- of the exception. MAY benull.- Returns:
- this
ExceptionBuilder. - Since:
- 0.1.0
-
setMessage
@Contract("null, _ -> fail; _, _ -> this") public ExceptionBuilder<T> setMessage(UnaryOperator<String> messageBuilder, @Nullable @Nullable String messageArg) Sets themessageto be used when instantiatingExceptionBuilder, by invokingmessageBuilderwithmessageArg.- Parameters:
messageBuilder- to invoke. MUST NOT benull.messageArg- to invoke with. MAY benull.- Returns:
- this
ExceptionBuilder. - Throws:
IllegalArgumentException- ifmessageBuilderisnull.- Since:
- 0.1.0
-
setMessage
@Contract("null, _, _ -> fail; _, _, _ -> this") public ExceptionBuilder<T> setMessage(BiFunction<String, String, String> messageBuilder, @Nullable @Nullable String messageArg1, @Nullable @Nullable String messageArg2) Sets themessageto be used when instantiatingExceptionBuilder, by invokingmessageBuilderwithmessageArg1andmessageArg2.- Parameters:
messageBuilder- to invoke. MUST NOT benull.messageArg1- to invoke with. MAY benull.messageArg2- to invoke with. MAY benull.- Returns:
- this
ExceptionBuilder. - Throws:
IllegalArgumentException- ifmessageBuilderisnull.- Since:
- 0.1.0
-
setMessage
@Contract("null, _ -> fail; _, _ -> this") public ExceptionBuilder<T> setMessage(String formattedString, String... messageArgs) Sets themessageto be used when instantiatingExceptionBuilder, by formattingformattedStringwith the format specifiersmessageArgs.- Parameters:
formattedString- to be formatted. MUST conform toString.formatted(Object...).messageArgs- to be used as format specifiers.- Returns:
- this
ExceptionBuilder. - Throws:
IllegalArgumentException- ifformattedStringisnull.- Since:
- 0.1.0
- See Also:
-
setMessage
@Contract("null, _ -> fail; _, _ -> this") public ExceptionBuilder<T> setMessage(MessageTemplates.OneArgTemplate messageTemplate, String messageArg) Sets themessageto be used when instantiatingExceptionBuilder, by applying themessageArgto themessageTemplate.- Parameters:
messageTemplate- to use.messageArg- to be supplied to themessageTemplate.- Returns:
- this
ExceptionBuilder. - Throws:
IllegalArgumentException- ifmessageTemplateisnull.- Since:
- 0.1.0
-
setMessage
@Contract("null, _, _ -> fail; _, _, _ -> this") public ExceptionBuilder<T> setMessage(MessageTemplates.TwoArgTemplate messageTemplate, String messageArgOne, String messageArgTwo) Sets themessageto be used when instantiatingExceptionBuilder, by applying themessageArgOneandmessageArgTwoto themessageTemplate.- Parameters:
messageTemplate- to use.messageArgOne- to be supplied to themessageTemplate.messageArgTwo- to be supplied to themessageTemplate.- Returns:
- this
ExceptionBuilder. - Throws:
IllegalArgumentException- ifmessageTemplateisnull.- Since:
- 0.1.0
-
setCause
@Contract(value="_ -> this", mutates="this") public ExceptionBuilder<T> setCause(@Nullable @Nullable Throwable cause) Sets thecauseto be used when instantiatingExceptionBuilder,- Parameters:
cause- of the exception. MAY benull.- Returns:
- this
ExceptionBuilder. - Since:
- 0.1.0
-
build
- Returns:
- the new
ExceptionBuilderinstance. - Since:
- 0.1.0
-