org.marketcetera.util.except
Class ExceptUtils

java.lang.Object
  extended by org.marketcetera.util.except.ExceptUtils

public final class ExceptUtils
extends Object

General-purpose utilities.

Since:
0.5.0
Version:
$Id: ExceptUtils.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com

Method Summary
static boolean areEqual(Throwable t, Object o)
          Checks whether the given throwable is equal to the given object.
static void checkInterruption()
          Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the default interruption message and no underlying cause.
static void checkInterruption(String message)
          Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the given interruption message, but without an underlying cause.
static void checkInterruption(Throwable cause)
          Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the default interruption message and the given underlying cause.
static void checkInterruption(Throwable cause, String message)
          Checks whether the calling thread has been interrupted, and, if so, throws an InterruptedException with the given interruption message and the given underlying cause.
static int getHashCode(Throwable t)
          Returns the hash code of the given throwable.
static boolean interrupt(Throwable throwable)
          If the given throwable is an interruption exception per isInterruptException(Throwable), then the calling thread is interrupted.
static boolean isInterruptException(Throwable throwable)
          Checks if the given throwable is an instance of InterruptedException, InterruptedIOException, I18NInterruptedException, or I18NInterruptedRuntimeException.
static boolean swallow(Throwable throwable)
          Swallows the given throwable.
static boolean swallow(Throwable throwable, Object category, I18NBoundMessage message)
          Swallows the given throwable.
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.
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.
static I18NRuntimeException wrapRuntime(Throwable throwable)
          If the given throwable is an interruption exception per isInterruptException(Throwable), then the throwable is wrapped inside a I18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted.
static I18NRuntimeException wrapRuntime(Throwable throwable, I18NBoundMessage message)
          If the given throwable is an interruption exception per isInterruptException(Throwable), then the throwable is wrapped inside a I18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

isInterruptException

public static boolean isInterruptException(Throwable throwable)
Checks if the given throwable is an instance of InterruptedException, InterruptedIOException, I18NInterruptedException, or I18NInterruptedRuntimeException.

Parameters:
throwable - The throwable.
Returns:
True if so.

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.

wrapRuntime

public static I18NRuntimeException wrapRuntime(Throwable throwable,
                                               I18NBoundMessage message)
If the given throwable is an interruption exception per isInterruptException(Throwable), then the throwable is wrapped inside a I18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted. Otherwise, an I18NRuntimeException is used to wrap the throwable. All arguments are passed as-is into the constructor of the wrapping exception.

Parameters:
throwable - The throwable.
message - The message.
Returns:
The wrapping exception.

wrapRuntime

public static I18NRuntimeException wrapRuntime(Throwable throwable)
If the given throwable is an interruption exception per isInterruptException(Throwable), then the throwable is wrapped inside a I18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted. Otherwise, an I18NRuntimeException is used to wrap the throwable. 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.


Copyright © 2012. All Rights Reserved.