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 void
Fails ifarg1
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.static void
Fails ifarg1
orarg2
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.static void
checkNull
(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) Fails ifarg1
,arg2
orarg3
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.static void
checkNull
(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4) Fails ifarg1
,arg2
,arg3
orarg4
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.static void
checkNull
(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5) Fails if any ofarg1
througharg5
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.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 ofarg1
througharg6
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.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 ofarg1
througharg7
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.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 ofarg1
througharg8
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.static void
checkNullOrBlank
(String messageTemplate, @Nullable String s) Fails if the strings
isnull
or blank, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.
-
Constructor Details
-
ErrorHandling
public ErrorHandling()
-
-
Method Details
-
checkNull
Fails ifarg1
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
arg1
- the argument to check for nullness- Throws:
IllegalArgumentException
- ifarg1
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
checkNull
@EnsuresNonNull({"#2","#3"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2) Fails ifarg1
orarg2
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
andarg2
arg1
- the first argument to check for nullnessarg2
- the second argument to check for nullness- Throws:
IllegalArgumentException
- ifarg1
orarg2
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
checkNull
@EnsuresNonNull({"#2","#3","#4"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) Fails ifarg1
,arg2
orarg3
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
,arg2
andarg3
arg1
- the first argument to check for nullnessarg2
- the second argument to check for nullnessarg3
- the third argument to check for nullness- Throws:
IllegalArgumentException
- ifarg1
,arg2
orarg3
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
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
,arg3
orarg4
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
,arg2
,arg3
andarg4
arg1
- 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
,arg3
orarg4
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
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 ofarg1
througharg5
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
througharg7
.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 ofarg1
throucharg5
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
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 ofarg1
througharg6
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
througharg7
.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 ofarg1
throucharg7
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
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 ofarg1
througharg7
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
througharg7
.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 ofarg1
throucharg7
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
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 ofarg1
througharg8
isnull
, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usingarg1
througharg7
.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 ofarg1
throucharg7
isnull
IllegalStateException
- ifmessageTemplate
isnull
-
checkNullOrBlank
@EnsuresNonNull("#2") public static void checkNullOrBlank(String messageTemplate, @Nullable String s) Fails if the strings
isnull
or blank, throwing anIllegalArgumentException
with a formatted message based onmessageTemplate
.- Parameters:
messageTemplate
- aString.format()
format string that will be formatted usings
s
- the string to check for nullness or blankness- Throws:
IllegalArgumentException
- ifs
isnull
or blank, i.e., empty or only containing whitespaceIllegalStateException
- ifmessageTemplate
isnull
-