org.geotoolkit.util.collection
Class BackingStoreException

Object
  extended by Throwable
      extended by Exception
          extended by RuntimeException
              extended by BackingStoreException
All Implemented Interfaces:
Serializable

public class BackingStoreException
extends RuntimeException

Thrown to indicate that an operation could not complete because of a failure in the backing store (a file or a database). This exception is thrown by collection implementations that are not allowed to throw checked exceptions. This exception usually has an IOException or a SQLException as its cause.

This method provides a unwrapOrRethrow(Class) convenience method which can be used for rethrowing the cause as in the example below. This allows client code to behave as if a Collection interface was allowed to declare checked exceptions.

void myMethod() throws IOException {
    Collection c = ...;
    try {
        c.doSomeStuff();
    } catch (BackingStoreException e) {
        throw e.unwrapOrRethrow(IOException.class);
    }
}

Since:
3.09 (derived from 2.3)
Version:
3.09
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
Serialized Form
Module:
utility/geotk-utility (download)    View source code for this class

Constructor Summary
BackingStoreException()
          Constructs a new exception with no detail message.
BackingStoreException(String message)
          Constructs a new exception with the specified detail message.
BackingStoreException(String message, Throwable cause)
          Constructs a new exception with the specified detail message and cause.
BackingStoreException(Throwable cause)
          Constructs a new exception with the specified cause.
 
Method Summary
<E extends Exception>
E
unwrapOrRethrow(Class<E> type)
          Returns the underlying cause as an exception of the given type, or rethrow the exception.
 
Methods inherited from class Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BackingStoreException

public BackingStoreException()
Constructs a new exception with no detail message.


BackingStoreException

public BackingStoreException(String message)
Constructs a new exception with the specified detail message.

Parameters:
message - the detail message, saved for later retrieval by the Throwable.getMessage() method.

BackingStoreException

public BackingStoreException(Throwable cause)
Constructs a new exception with the specified cause.

Parameters:
cause - the cause, saved for later retrieval by the Throwable.getCause() method.

BackingStoreException

public BackingStoreException(String message,
                             Throwable cause)
Constructs a new exception with the specified detail message and cause.

Parameters:
message - the detail message, saved for later retrieval by the Throwable.getMessage() method.
cause - the cause, saved for later retrieval by the Throwable.getCause() method.
Method Detail

unwrapOrRethrow

public <E extends Exception> E unwrapOrRethrow(Class<E> type)
                                    throws RuntimeException,
                                           BackingStoreException
Returns the underlying cause as an exception of the given type, or rethrow the exception. More specifically, this method makes the following choices:

This method should be used as in the example below:

void myMethod() throws IOException {
    Collection c = ...;
    try {
        c.doSomeStuff();
    } catch (BackingStoreException e) {
        throw e.unwrapOrRethrow(IOException.class);
    }
}

Type Parameters:
E - The type of the exception to unwrap.
Parameters:
type - The type of the exception to unwrap.
Returns:
The cause as an exception of the given type (never null).
Throws:
RuntimeException - If the cause is an instance of RuntimeException, in which case that instance is rethrown.
BackingStoreException - if the cause is neither the given type or an instance of RuntimeException, in which case this exception is rethrown.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.