Class ErrorHandling
java.lang.Object
com.reallifedeveloper.common.domain.ErrorHandling
Utility class for simplifying error handling.
- Author:
- RealLifeDeveloper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidFails ifarg1isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidFails ifarg1orarg2isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidcheckNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) Fails ifarg1,arg2orarg3isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidcheckNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4) Fails ifarg1,arg2,arg3orarg4isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidcheckNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5) Fails if any ofarg1througharg5isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidcheckNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5, @Nullable Object arg6) Fails if any ofarg1througharg6isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidcheckNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5, @Nullable Object arg6, @Nullable Object arg7) Fails if any ofarg1througharg7isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidcheckNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5, @Nullable Object arg6, @Nullable Object arg7, @Nullable Object arg8) Fails if any ofarg1througharg8isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.static voidcheckNullOrBlank(String messageTemplate, @Nullable String s) Fails if the stringsisnullor blank, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.
-
Constructor Details
-
ErrorHandling
public ErrorHandling()
-
-
Method Details
-
checkNull
Fails ifarg1isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1arg1- the argument to check for nullness- Throws:
IllegalArgumentException- ifarg1isnullIllegalStateException- ifmessageTemplateisnull
-
checkNull
@EnsuresNonNull({"#2","#3"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2) Fails ifarg1orarg2isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1andarg2arg1- the first argument to check for nullnessarg2- the second argument to check for nullness- Throws:
IllegalArgumentException- ifarg1orarg2isnullIllegalStateException- ifmessageTemplateisnull
-
checkNull
@EnsuresNonNull({"#2","#3","#4"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) Fails ifarg1,arg2orarg3isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1,arg2andarg3arg1- the first argument to check for nullnessarg2- the second argument to check for nullnessarg3- the third argument to check for nullness- Throws:
IllegalArgumentException- ifarg1,arg2orarg3isnullIllegalStateException- ifmessageTemplateisnull
-
checkNull
@EnsuresNonNull({"#2","#3","#4","#5"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4) Fails ifarg1,arg2,arg3orarg4isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1,arg2,arg3andarg4arg1- the first argument to check for nullnessarg2- the second argument to check for nullnessarg3- the third argument to check for nullnessarg4- the third argument to check for nullness- Throws:
IllegalArgumentException- ifarg1,arg2,arg3orarg4isnullIllegalStateException- ifmessageTemplateisnull
-
checkNull
@EnsuresNonNull({"#2","#3","#4","#5","#6"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5) Fails if any ofarg1througharg5isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1througharg5.arg1- the first argument to check for nullnessarg2- the second argument to check for nullnessarg3- the third argument to check for nullnessarg4- the fourth argument to check for nullnessarg5- the fifth argument to check for nullness- Throws:
IllegalArgumentException- if any ofarg1througharg5isnullIllegalStateException- ifmessageTemplateisnull
-
checkNull
@EnsuresNonNull({"#2","#3","#4","#5","#6","#7"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5, @Nullable Object arg6) Fails if any ofarg1througharg6isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1througharg6.arg1- the first argument to check for nullnessarg2- the second argument to check for nullnessarg3- the third argument to check for nullnessarg4- the fourth argument to check for nullnessarg5- the fifth argument to check for nullnessarg6- the sixth argument to check for nullness- Throws:
IllegalArgumentException- if any ofarg1througharg6isnullIllegalStateException- ifmessageTemplateisnull
-
checkNull
@EnsuresNonNull({"#2","#3","#4","#5","#6","#7","#8"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5, @Nullable Object arg6, @Nullable Object arg7) Fails if any ofarg1througharg7isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1througharg7.arg1- the first argument to check for nullnessarg2- the second argument to check for nullnessarg3- the third argument to check for nullnessarg4- the fourth argument to check for nullnessarg5- the fifth argument to check for nullnessarg6- the sixth argument to check for nullnessarg7- the seventh argument to check for nullness- Throws:
IllegalArgumentException- if any ofarg1througharg7isnullIllegalStateException- ifmessageTemplateisnull
-
checkNull
@EnsuresNonNull({"#2","#3","#4","#5","#6","#7","#8","#9"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5, @Nullable Object arg6, @Nullable Object arg7, @Nullable Object arg8) Fails if any ofarg1througharg8isnull, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingarg1througharg8.arg1- the first argument to check for nullnessarg2- the second argument to check for nullnessarg3- the third argument to check for nullnessarg4- the fourth argument to check for nullnessarg5- the fifth argument to check for nullnessarg6- the sixth argument to check for nullnessarg7- the seventh argument to check for nullnessarg8- the eigth argument to check for nullness- Throws:
IllegalArgumentException- if any ofarg1througharg8isnullIllegalStateException- ifmessageTemplateisnull
-
checkNullOrBlank
@EnsuresNonNull("#2") public static void checkNullOrBlank(String messageTemplate, @Nullable String s) Fails if the stringsisnullor blank, throwing anIllegalArgumentExceptionwith a formatted message based onmessageTemplate.- Parameters:
messageTemplate- aString.format()format string that will be formatted usingss- the string to check for nullness or blankness- Throws:
IllegalArgumentException- ifsisnullor blank, i.e., empty or only containing whitespaceIllegalStateException- ifmessageTemplateisnull
-