com.pelzer.util
Class Absorb

java.lang.Object
  extended by com.pelzer.util.Absorb

public class Absorb
extends Object

Utility class to absorb exceptions in certain cases such as sleeping and in catch blocks.


Nested Class Summary
static interface Absorb.IgnoredExceptionListener
           
 
Constructor Summary
Absorb()
           
 
Method Summary
static void addIgnoredExceptionListener(Absorb.IgnoredExceptionListener listener)
           
static void ignore(Throwable ignored)
          Not an exactly perfect name, but basically takes the given exception and logs it under this class's logger, which is silenced by default.
static void removeIgnoredExceptionListener(Absorb.IgnoredExceptionListener listener)
           
static void rethrow(Throwable ex)
          Wraps the passed exception and then rethrows it wrapped in a runtime exception.
static void sleep(long milliseconds)
          Shortcut to #sleep(TimeUnit.MILLISECONDS, long)
static void sleep(TimeUnit timeUnit, long units)
          Sleeps in exactly the same way as calling timeUnit.sleep(units), but absorbs any InterruptedException and exits normally.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Absorb

public Absorb()
Method Detail

sleep

public static void sleep(TimeUnit timeUnit,
                         long units)
Sleeps in exactly the same way as calling timeUnit.sleep(units), but absorbs any InterruptedException and exits normally.


sleep

public static void sleep(long milliseconds)
Shortcut to #sleep(TimeUnit.MILLISECONDS, long)


ignore

public static void ignore(Throwable ignored)
Not an exactly perfect name, but basically takes the given exception and logs it under this class's logger, which is silenced by default. Useful for making sure you don't have empty catch, but you don't have to write a bunch of boilerplate to do something with the tossed exception.


addIgnoredExceptionListener

public static void addIgnoredExceptionListener(Absorb.IgnoredExceptionListener listener)

removeIgnoredExceptionListener

public static void removeIgnoredExceptionListener(Absorb.IgnoredExceptionListener listener)

rethrow

public static void rethrow(Throwable ex)
Wraps the passed exception and then rethrows it wrapped in a runtime exception.



Copyright © 2012. All Rights Reserved.