Class ErrorHandling

java.lang.Object
com.reallifedeveloper.common.domain.ErrorHandling

public class ErrorHandling extends Object
Utility class for simplifying error handling.
Author:
RealLifeDeveloper
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkNull(String messageTemplate, @Nullable Object arg1)
    Fails if arg1 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    static void
    checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2)
    Fails if arg1 or arg2 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    static void
    checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3)
    Fails if arg1, arg2 or arg3 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    static void
    checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4)
    Fails if arg1, arg2, arg3 or arg4 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    static void
    checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4, @Nullable Object arg5)
    Fails if any of arg1 through arg5 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    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 of arg1 through arg6 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    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 of arg1 through arg7 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    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 of arg1 through arg8 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
    static void
    checkNullOrBlank(String messageTemplate, @Nullable String s)
    Fails if the string s is null or blank, throwing an IllegalArgumentException with a formatted message based on messageTemplate.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ErrorHandling

      public ErrorHandling()
  • Method Details

    • checkNull

      @EnsuresNonNull("#2") public static void checkNull(String messageTemplate, @Nullable Object arg1)
      Fails if arg1 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1
      arg1 - the argument to check for nullness
      Throws:
      IllegalArgumentException - if arg1 is null
      IllegalStateException - if messageTemplate is null
    • checkNull

      @EnsuresNonNull({"#2","#3"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2)
      Fails if arg1 or arg2 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1 and arg2
      arg1 - the first argument to check for nullness
      arg2 - the second argument to check for nullness
      Throws:
      IllegalArgumentException - if arg1 or arg2 is null
      IllegalStateException - if messageTemplate is null
    • checkNull

      @EnsuresNonNull({"#2","#3","#4"}) public static void checkNull(String messageTemplate, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3)
      Fails if arg1, arg2 or arg3 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1, arg2 and arg3
      arg1 - the first argument to check for nullness
      arg2 - the second argument to check for nullness
      arg3 - the third argument to check for nullness
      Throws:
      IllegalArgumentException - if arg1, arg2 or arg3 is null
      IllegalStateException - if messageTemplate is null
    • 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 if arg1, arg2, arg3 or arg4 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1, arg2, arg3 and arg4
      arg1 - the first argument to check for nullness
      arg2 - the second argument to check for nullness
      arg3 - the third argument to check for nullness
      arg4 - the third argument to check for nullness
      Throws:
      IllegalArgumentException - if arg1, arg2, arg3 or arg4 is null
      IllegalStateException - if messageTemplate is null
    • 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 of arg1 through arg5 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1 through arg7.
      arg1 - the first argument to check for nullness
      arg2 - the second argument to check for nullness
      arg3 - the third argument to check for nullness
      arg4 - the fourth argument to check for nullness
      arg5 - the fifth argument to check for nullness
      Throws:
      IllegalArgumentException - if any of arg1 throuch arg5 is null
      IllegalStateException - if messageTemplate is null
    • 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 of arg1 through arg6 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1 through arg7.
      arg1 - the first argument to check for nullness
      arg2 - the second argument to check for nullness
      arg3 - the third argument to check for nullness
      arg4 - the fourth argument to check for nullness
      arg5 - the fifth argument to check for nullness
      arg6 - the sixth argument to check for nullness
      Throws:
      IllegalArgumentException - if any of arg1 throuch arg7 is null
      IllegalStateException - if messageTemplate is null
    • 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 of arg1 through arg7 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1 through arg7.
      arg1 - the first argument to check for nullness
      arg2 - the second argument to check for nullness
      arg3 - the third argument to check for nullness
      arg4 - the fourth argument to check for nullness
      arg5 - the fifth argument to check for nullness
      arg6 - the sixth argument to check for nullness
      arg7 - the seventh argument to check for nullness
      Throws:
      IllegalArgumentException - if any of arg1 throuch arg7 is null
      IllegalStateException - if messageTemplate is null
    • 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 of arg1 through arg8 is null, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using arg1 through arg7.
      arg1 - the first argument to check for nullness
      arg2 - the second argument to check for nullness
      arg3 - the third argument to check for nullness
      arg4 - the fourth argument to check for nullness
      arg5 - the fifth argument to check for nullness
      arg6 - the sixth argument to check for nullness
      arg7 - the seventh argument to check for nullness
      arg8 - the eigth argument to check for nullness
      Throws:
      IllegalArgumentException - if any of arg1 throuch arg7 is null
      IllegalStateException - if messageTemplate is null
    • checkNullOrBlank

      @EnsuresNonNull("#2") public static void checkNullOrBlank(String messageTemplate, @Nullable String s)
      Fails if the string s is null or blank, throwing an IllegalArgumentException with a formatted message based on messageTemplate.
      Parameters:
      messageTemplate - a String.format() format string that will be formatted using s
      s - the string to check for nullness or blankness
      Throws:
      IllegalArgumentException - if s is null or blank, i.e., empty or only containing whitespace
      IllegalStateException - if messageTemplate is null