Package org.marketcetera.util.except
Class ExceptUtils
- java.lang.Object
-
- org.marketcetera.util.except.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 Summary
Constructors Modifier Constructor Description privateExceptUtils()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareEqual(Throwable t, Object o)Checks whether the given throwable is equal to the given object.static voidcheckInterruption()Checks whether the calling thread has been interrupted, and, if so, throws anInterruptedExceptionwith the default interruption message and no underlying cause.static voidcheckInterruption(String message)Checks whether the calling thread has been interrupted, and, if so, throws anInterruptedExceptionwith the given interruption message, but without an underlying cause.static voidcheckInterruption(Throwable cause)Checks whether the calling thread has been interrupted, and, if so, throws anInterruptedExceptionwith the default interruption message and the given underlying cause.static voidcheckInterruption(Throwable cause, String message)Checks whether the calling thread has been interrupted, and, if so, throws anInterruptedExceptionwith the given interruption message and the given underlying cause.static intgetHashCode(Throwable t)Returns the hash code of the given throwable.static StringgetRootCauseMessage(Throwable inException)Gets the root cause message.static booleaninterrupt(Throwable throwable)If the given throwable is an interruption exception perisInterruptException(Throwable), then the calling thread is interrupted.static booleanisInterruptException(Throwable throwable)Checks if the given throwable is an instance ofInterruptedException,InterruptedIOException,I18NInterruptedException, orI18NInterruptedRuntimeException.static booleanswallow(Throwable throwable)Swallows the given throwable.static booleanswallow(Throwable throwable, Object category, I18NBoundMessage message)Swallows the given throwable.static I18NExceptionwrap(Throwable throwable)If the given throwable is an interruption exception perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedException, and this exception is returned; also, the calling thread is interrupted.static I18NExceptionwrap(Throwable throwable, I18NBoundMessage message)If the given throwable is an interruption exception perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedException, and this exception is returned; also, the calling thread is interrupted.static I18NRuntimeExceptionwrapRuntime(Throwable throwable)If the given throwable is an interruption exception perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted.static I18NRuntimeExceptionwrapRuntime(Throwable throwable, I18NBoundMessage message)If the given throwable is an interruption exception perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted.
-
-
-
Method Detail
-
checkInterruption
public static void checkInterruption() throws InterruptedExceptionChecks whether the calling thread has been interrupted, and, if so, throws anInterruptedExceptionwith 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 anInterruptedExceptionwith 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 anInterruptedExceptionwith 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 anInterruptedExceptionwith 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 ofInterruptedException,InterruptedIOException,I18NInterruptedException, orI18NInterruptedRuntimeException.- Parameters:
throwable- The throwable.- Returns:
- True if so.
-
interrupt
public static boolean interrupt(Throwable throwable)
If the given throwable is an interruption exception perisInterruptException(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 perisInterruptException(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 perisInterruptException(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 perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedException, and this exception is returned; also, the calling thread is interrupted. Otherwise, anI18NExceptionis 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 perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedException, and this exception is returned; also, the calling thread is interrupted. Otherwise, anI18NExceptionis 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 perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted. Otherwise, anI18NRuntimeExceptionis 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 perisInterruptException(Throwable), then the throwable is wrapped inside aI18NInterruptedRuntimeException, and this exception is thrown; also, the calling thread is interrupted. Otherwise, anI18NRuntimeExceptionis 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 ofareEqual(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.
-
-