Package org.synchronoss.cpo.core.helper
Class ExceptionHelper
java.lang.Object
org.synchronoss.cpo.core.helper.ExceptionHelper
Static helpers for extracting readable messages from a
Throwable and for normalizing
arbitrary exceptions into CpoException.
getMessage/getLocalizedMessage fall back to the exception's cause when the exception itself carries no message, since CPO frequently
wraps lower-level exceptions (e.g. SQLException) whose message lives on the cause.
- Author:
- dberry
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringGets the localized message of the given exception, falling back to its cause's localized message when the exception itself has none.static StringGets the message of the given exception, falling back to its cause's message when the exception itself has none.static voidreThrowCpoException(Throwable e, String message) Rethrowseas aCpoException: if it already is one it is rethrown unchanged, otherwise it is wrapped in a newCpoExceptionwith the given message.
-
Method Details
-
getMessage
Gets the message of the given exception, falling back to its cause's message when the exception itself has none.- Parameters:
e- the exception to extract a message from; ifnullan empty string is returned- Returns:
- the exception's message, its cause's message, or
""if neither is present
-
getLocalizedMessage
Gets the localized message of the given exception, falling back to its cause's localized message when the exception itself has none.- Parameters:
e- the exception to extract a localized message from; ifnullan empty string is returned- Returns:
- the exception's localized message, its cause's localized message, or
""if neither is present
-
reThrowCpoException
Rethrowseas aCpoException: if it already is one it is rethrown unchanged, otherwise it is wrapped in a newCpoExceptionwith the given message.- Parameters:
e- the exception to rethrow or wrapmessage- the message to use whenemust be wrapped; ignored ifeis already aCpoException- Throws:
CpoException- always, eithereitself or a new instance wrapping it
-