Class ExceptionUtil

java.lang.Object
jp.ecuacion.lib.core.util.ExceptionUtil

public class ExceptionUtil extends Object
Provides available utilities for Exceptions including AppExceptions.
  • Constructor Details

    • ExceptionUtil

      public ExceptionUtil()
  • Method Details

    • getExceptionMessage

      @Nonnull public List<String> getExceptionMessage(@RequireNonnull Throwable throwable, boolean needsDetails)
      Returns exception message for 1 exception.

      This method covers all the exceptions including Java standard exceptions, ConstraintViolationException used in Bean Validation and AppExceptions defined in this library.

      One exception normally has one message, but one ConstraintViolationException can have multiple messages so the return type is not a String, but a List<String>.

      Parameters:
      throwable - throwable
      needsDetails - Sets if detail message is needed. This is true with log output or batch processing. False when you show the message on screen.
      Returns:
      a list of messages
    • getExceptionMessage

      @Nonnull public List<String> getExceptionMessage(@RequireNonnull Throwable throwable, @Nullable Locale locale, boolean needsDetails)
      Returns exception message for 1 exception.

      This method covers all the exceptions including Java standard exceptions, ConstraintViolationException used in Bean Validation and AppExceptions defined in this library.

      One exception normally has one message, but one ConstraintViolationException can have multiple messages so the return type is not a String, but a List<String>.

      Parameters:
      throwable - throwable
      locale - locale, may be null which is treated as Locale.getDefault().
      needsDetails - Sets if detail message is needed. This is true with log output or batch processing. False when you show the message on screen.
      Returns:
      a list of messages
    • getExceptionListWithMessages

      @Nonnull public List<Throwable> getExceptionListWithMessages(@RequireNonnull Throwable throwable)
      Returns listed exceptions with messages.

      This is used for log output to see error messages easily.

      This is not used for online because in online apps messages shown to users is only SingleAppExceptions.

      Parameters:
      throwable - throwable
      Returns:
      a list of Throwables
    • getSingleAppExceptionList

      @Nonnull public List<SingleAppException> getSingleAppExceptionList(@RequireNonnull AppException appException)
      Returns listed SingleAppExceptions (= AppExceptions with messages).

      This is not used for online

      Parameters:
      appException - AppException
      Returns:
      list of SingleAppException
    • getAppExceptionMessageList

      @Nonnull public List<String> getAppExceptionMessageList(@RequireNonnull AppException appException, @Nullable Locale locale)
      Returns listed SingleAppExceptions (= AppExceptions with messages).

      This is used for online.

      The overload method with RuntimeAppException won't be created because getCause() of RuntimeAppException is AppException and it is not needed by then.

      Parameters:
      appException - AppException
      locale - locale, may be null which is treated as Locale.getDefault().
      Returns:
      list of SingleAppException
    • getErrLogString

      @Nonnull public String getErrLogString(@RequireNonnull Throwable throwable, @Nullable String additionalMessage, @Nullable Locale locale)
      Returns strings or error log.
      Parameters:
      throwable - throwable
      additionalMessage - additional message, may be null if no additionalMessage is needed. In the case of null no additional message is output.
      locale - locale, may be null which is treated as Locale.getDefault().
      Returns:
      error log string