Class ExceptionUtil
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiongetAppExceptionMessageList(AppException appException, Locale locale) Returns listed SingleAppExceptions (= AppExceptions with messages).getAppExceptionMessageList(AppException appException, Locale locale, boolean needsItemName) Returns listed SingleAppExceptions (= AppExceptions with messages).static StringgetErrLogString(Throwable throwable, String additionalMessage, Locale locale) Returns strings or error log.static StringgetErrLogString(Throwable throwable, String additionalMessage, Locale locale, Integer packagesShown) Returns strings or error log.getExceptionListWithMessages(Throwable throwable) Returns listed exceptions with messages.getExceptionMessage(Throwable throwable, boolean needsDetails) Returns exception message for 1 exception.getExceptionMessage(Throwable throwable, Locale locale, boolean needsDetails) Returns exception message for 1 exception.getExceptionMessage(Throwable throwable, Locale locale, boolean needsDetails, boolean needsItemName) Returns exception message for 1 exception.static voidgetMessageAndStackTraceStringRecursively(StringBuilder sb, Throwable th, Locale locale, Integer packagesShown) Adds Throwable message and stackTrace string to argument stringBuilder for a throwable and its causes.static List<SingleAppException> getSingleAppExceptionList(AppException appException) Returns listed SingleAppExceptions (= AppExceptions with messages).
-
Field Details
-
SYSTEM_ERROR_OCCURED_SIGN
- See Also:
-
-
Method Details
-
getExceptionMessage
@Nonnull public static 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 Jakarta 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 aList<String>.- Parameters:
throwable- throwableneedsDetails- 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 static 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 Jakarta 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 aList<String>.- Parameters:
throwable- throwablelocale- locale, may benullwhich is treated asLocale.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
-
getExceptionMessage
@Nonnull public static List<String> getExceptionMessage(@RequireNonnull Throwable throwable, @Nullable Locale locale, boolean needsDetails, boolean needsItemName) Returns exception message for 1 exception.This method covers all the exceptions including Java standard exceptions, ConstraintViolationException used in Jakarta 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 aList<String>.- Parameters:
throwable- throwablelocale- locale, may benullwhich is treated asLocale.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.needsItemName- true when itemName needed for ValidationAppException messages.- Returns:
- a list of messages
-
getExceptionListWithMessages
@Nonnull public static 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 static 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 static 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- AppExceptionlocale- locale, may benullwhich is treated asLocale.getDefault().- Returns:
- list of SingleAppException
-
getAppExceptionMessageList
@Nonnull public static List<String> getAppExceptionMessageList(@RequireNonnull AppException appException, @Nullable Locale locale, boolean needsItemName) 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- AppExceptionlocale- locale, may benullwhich is treated asLocale.getDefault().needsItemName- true when itemName needed for ValidationAppException messages.- Returns:
- list of SingleAppException
-
getErrLogString
@Nonnull public static String getErrLogString(@RequireNonnull Throwable throwable, @Nullable String additionalMessage, @Nullable Locale locale) Returns strings or error log.- Parameters:
throwable- throwableadditionalMessage- additional message, may benullif noadditionalMessageis needed. In the case ofnullno additional message is output.locale- locale, may benullwhich is treated asLocale.getDefault().- Returns:
- error log string
-
getErrLogString
@Nonnull public static String getErrLogString(@RequireNonnull Throwable throwable, @Nullable String additionalMessage, @Nullable Locale locale, @Nullable Integer packagesShown) Returns strings or error log.- Parameters:
throwable- throwableadditionalMessage- additional message, may benullif noadditionalMessageis needed. In the case ofnullno additional message is output.locale- locale, may benullwhich is treated asLocale.getDefault().packagesShown- packages shown in the stack traces. This is used when the log displaying area is small.- Returns:
- error log string
-
getMessageAndStackTraceStringRecursively
public static void getMessageAndStackTraceStringRecursively(StringBuilder sb, Throwable th, Locale locale, Integer packagesShown) Adds Throwable message and stackTrace string to argument stringBuilder for a throwable and its causes.- Parameters:
sb- StringBuilderth- throwablelocale- locale, may be nullpackagesShown- null means all package of a class is shown like "at jp.ecuacion.lib.core.util.ExceptionUtil.main(ExceptionUtil.java:468)". "0" shows no packages like "at ..main(ExceptionUtil.java:468)". "1" shows 1 package part like "at jp...main(ExceptionUtil.java:468)".
-