Class ExceptUtils


  • public final class ExceptUtils
    extends Object
    General-purpose utilities.
    Since:
    0.5.0
    Version:
    $Id: ExceptUtils.java 16914 2014-06-24 21:27:56Z colin $
    Author:
    tlerios@marketcetera.com
    • Constructor Detail

      • ExceptUtils

        private ExceptUtils()
        Constructor. It is private so that no instances can be created.
    • Method Detail

      • checkInterruption

        public static void checkInterruption()
                                      throws InterruptedException
        Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the default interruption message and no underlying cause. The interrupted status of the thread is cleared.
        Throws:
        InterruptedException - Thrown if the calling thread was interrupted.
      • checkInterruption

        public static void checkInterruption​(String message)
                                      throws InterruptedException
        Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the given interruption message, but without an underlying cause. The interrupted status of the thread is cleared.
        Parameters:
        message - The message.
        Throws:
        InterruptedException - Thrown if the calling thread was interrupted.
      • checkInterruption

        public static void checkInterruption​(Throwable cause)
                                      throws InterruptedException
        Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the default interruption message and the given underlying cause. The given underlying cause is set on the thrown exception. The interrupted status of the thread is cleared.
        Parameters:
        cause - The cause.
        Throws:
        InterruptedException - Thrown if the calling thread was interrupted.
      • checkInterruption

        public static void checkInterruption​(Throwable cause,
                                             String message)
                                      throws InterruptedException
        Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the given interruption message and the given underlying cause. The given underlying cause is set on the thrown exception. The interrupted status of the thread is cleared.
        Parameters:
        cause - The cause.
        message - The message.
        Throws:
        InterruptedException - Thrown if the calling thread was interrupted.
      • interrupt

        public static boolean interrupt​(Throwable throwable)
        If the given throwable is an interruption exception per isInterruptException(Throwable), then the calling thread is interrupted. Otherwise, this is a no-op.
        Parameters:
        throwable - The throwable.
        Returns:
        True if the calling thread was interrupted.
      • swallow

        public static boolean swallow​(Throwable throwable,
                                      Object category,
                                      I18NBoundMessage message)
        Swallows the given throwable. It logs the given parameterized message and throwable under the given logging category at the warning level. Also, if the given throwable is an interruption exception per isInterruptException(Throwable), then the calling thread is interrupted.
        Parameters:
        throwable - The throwable.
        category - The category.
        message - The message.
        Returns:
        True if the calling thread was interrupted.
      • swallow

        public static boolean swallow​(Throwable throwable)
        Swallows the given throwable. It logs a default message alongside the throwable at the warning level. Also, if the given throwable is an interruption exception per isInterruptException(Throwable), then the calling thread is interrupted.
        Parameters:
        throwable - The throwable.
        Returns:
        True if the calling thread was interrupted.
      • wrap

        public static I18NException wrap​(Throwable throwable,
                                         I18NBoundMessage message)
        If the given throwable is an interruption exception per isInterruptException(Throwable), then the throwable is wrapped inside a I18NInterruptedException, and this exception is returned; also, the calling thread is interrupted. Otherwise, an I18NException is used to wrap the throwable, and returned. All arguments are passed as-is into the constructor of the wrapping exception.
        Parameters:
        throwable - The throwable.
        message - The message.
        Returns:
        The wrapping exception.
      • wrap

        public static I18NException wrap​(Throwable throwable)
        If the given throwable is an interruption exception per isInterruptException(Throwable), then the throwable is wrapped inside a I18NInterruptedException, and this exception is returned; also, the calling thread is interrupted. Otherwise, an I18NException is used to wrap the throwable, and returned. All arguments are passed as-is into the constructor of the wrapping exception.
        Parameters:
        throwable - The throwable.
        Returns:
        The wrapping exception.
      • getHashCode

        public static int getHashCode​(Throwable t)
        Returns the hash code of the given throwable. The result matches the equality definition of areEqual(Throwable,Object).
        Parameters:
        t - The throwable.
        Returns:
        The hash code.
      • areEqual

        public static boolean areEqual​(Throwable t,
                                       Object o)
        Checks whether the given throwable is equal to the given object. Equality requires identical classes, equal messages, and equal causes.
        Parameters:
        t - The throwable. It may be null.
        o - The object. It may be null.
        Returns:
        True if so.
      • getRootCauseMessage

        public static String getRootCauseMessage​(Throwable inException)
        Gets the root cause message.
        Parameters:
        inException - a Throwable value
        Returns:
        a String value or null