Package org.apache.sis.util.collection
Class BackingStoreException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.apache.sis.util.collection.BackingStoreException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MetadataVisitorException
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 implementations of API (collection, streams,
etc. that are not allowed to throw checked exceptions.
This exception usually has an Relationship with
JDK8 provides a
IOException
or a SQLException
as its cause.
This method provides a unwrapOrRethrow(Class)
convenience method which can be used
for re-throwing the cause as in the example below. This allows client code to behave as if a
Collection
interface was allowed to declare checked exceptions.
Relationship with java.io.UncheckedIOException
JDK8 provides a UncheckedIOException
which partially overlaps
the purpose of this BackingStoreException
. While Apache SIS still uses
BackingStoreException
as a general mechanism for any kind of checked exceptions,
client code would be well advised to catch both kind of exceptions for robustness.- Since:
- 0.3
- Version:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
For cross-version compatibility. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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
Modifier and TypeMethodDescriptionprivate void
copySuppressed
(Throwable cause) Copies suppressed exceptions to the given target.<E extends Exception>
EunwrapOrRethrow
(Class<E> type) Returns the underlying cause as an exception of the given type, or re-throw the exception.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
-
Constructor Details
-
BackingStoreException
public BackingStoreException()Constructs a new exception with no detail message. -
BackingStoreException
Constructs a new exception with the specified detail message.- Parameters:
message
- the detail message, saved for later retrieval by theThrowable.getMessage()
method.
-
BackingStoreException
Constructs a new exception with the specified cause.- Parameters:
cause
- the cause, saved for later retrieval by theThrowable.getCause()
method.
-
BackingStoreException
Constructs a new exception with the specified detail message and cause.- Parameters:
message
- the detail message, saved for later retrieval by theThrowable.getMessage()
method.cause
- the cause, saved for later retrieval by theThrowable.getCause()
method.
-
-
Method Details
-
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 re-throw the exception. More specifically, this method makes the following choices:- If the cause is an instance of the given type, returns the cause.
- Otherwise if the cause is an instance of
RuntimeException
, throws that exception. - Otherwise re-throws
this
.
<E>
orRuntimeException
cause, then this method copies the suppressed exceptions into the cause before to throw the cause.- 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 ofRuntimeException
, in which case that instance is re-thrown.BackingStoreException
- if the cause is neither the given type or an instance ofRuntimeException
, in which casethis
exception is re-thrown.
-
copySuppressed
Copies suppressed exceptions to the given target. This method is invoked before the cause is re-thrown. Current version does not verify that this copy operation does not create duplicated values. Most of the time, this exception has no suppressed exceptions and this method does nothing.This copy operation is useful if a
BackingStoreException
was thrown inside a try-with-resource block, especially when theAutoCloseable
is aStream
.
-