Class ExceptionHelper

java.lang.Object
org.synchronoss.cpo.core.helper.ExceptionHelper

public class ExceptionHelper extends Object
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 Details

    • getMessage

      public static String getMessage(Throwable e)
      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; if null an empty string is returned
      Returns:
      the exception's message, its cause's message, or "" if neither is present
    • getLocalizedMessage

      public static String getLocalizedMessage(Throwable e)
      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; if null an empty string is returned
      Returns:
      the exception's localized message, its cause's localized message, or "" if neither is present
    • reThrowCpoException

      public static void reThrowCpoException(Throwable e, String message) throws CpoException
      Rethrows e as a CpoException: if it already is one it is rethrown unchanged, otherwise it is wrapped in a new CpoException with the given message.
      Parameters:
      e - the exception to rethrow or wrap
      message - the message to use when e must be wrapped; ignored if e is already a CpoException
      Throws:
      CpoException - always, either e itself or a new instance wrapping it