public class ExceptionHandler<T> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
ExceptionHandler.ExceptionWrapper<T,E extends Throwable> |
static interface |
ExceptionHandler.ThrowingConsumer<T,E extends Throwable> |
static interface |
ExceptionHandler.ThrowingFunction<T,R,E extends Throwable> |
Modifier | Constructor and Description |
---|---|
protected |
ExceptionHandler(T value,
Exception exception)
Private class constructor.
|
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns the contained object.
|
ExceptionHandler<T> |
handleOMEROException(String message)
Throws:
AccessException if DSAccessException was caught
ServiceException if DSOutOfServiceException was caught
The appropriate exception if ServerError was caught (see handleOMEROException(java.lang.Throwable, java.lang.String) )
|
static void |
handleOMEROException(Throwable throwable,
String message)
Checks the cause of an exception on OMERO and throws:
ServiceException if the cause was:
SessionException
AuthenticationException
ResourceError
AccessException if the cause was:
SecurityViolation
Anything else
See Facility.handleException(java.lang.Object, java.lang.Throwable, java.lang.String) |
ExceptionHandler<T> |
handleServerAndService(String message)
Checks if a ServerError or a DSOutOfService was thrown and handles the exception according to the cause.
|
static <I,R> ExceptionHandler<R> |
of(I input,
ExceptionHandler.ThrowingFunction<? super I,? extends R,? extends Exception> mapper)
Creates an ExceptionHandler from an object and a function.
|
static <I> ExceptionHandler<I> |
ofConsumer(I input,
ExceptionHandler.ThrowingConsumer<? super I,? extends Exception> consumer)
Creates an ExceptionHandler from an object and a function with no return value.
|
void |
rethrow()
Rethrows exception if one was caught (to not swallow it).
|
<E extends Throwable> |
rethrow(Class<E> type)
Throws an exception from the specified type, if one was caught.
|
<E extends Throwable,F extends Throwable> |
rethrow(Class<E> type,
ExceptionHandler.ExceptionWrapper<? super E,? extends F> mapper,
String message)
Throws an exception converted from the specified type, if one was caught.
|
String |
toString() |
public static <I,R> ExceptionHandler<R> of(I input, ExceptionHandler.ThrowingFunction<? super I,? extends R,? extends Exception> mapper)
I
- Input argument type.R
- Returned object type.input
- Object to process.mapper
- Lambda to apply on object.public static <I> ExceptionHandler<I> ofConsumer(I input, ExceptionHandler.ThrowingConsumer<? super I,? extends Exception> consumer)
I
- Input argument type.input
- Object to process.consumer
- Lambda to apply on object.public static void handleOMEROException(Throwable throwable, String message) throws ServiceException, AccessException
ServiceException
if the cause was:
AccessException
if the cause was:
SecurityViolation
See Facility.handleException(java.lang.Object, java.lang.Throwable, java.lang.String)
throwable
- The exception.message
- Error message.ServiceException
- Cannot connect to OMERO.AccessException
- Cannot access data.public <E extends Throwable> ExceptionHandler<T> rethrow(Class<E> type) throws E extends Throwable
E
- The type of the exception.type
- The exception class.E
- An exception from the specified type.E extends Throwable
public <E extends Throwable,F extends Throwable> ExceptionHandler<T> rethrow(Class<E> type, ExceptionHandler.ExceptionWrapper<? super E,? extends F> mapper, String message) throws F extends Throwable
E
- The type of the exception.F
- The type of the exception thrown.type
- The exception class.mapper
- Lambda to convert the caught exception.message
- Error message.F
- A converted Exception.F extends Throwable
public ExceptionHandler<T> handleServerAndService(String message) throws ServiceException, AccessException
message
- Error message.ServiceException
- Cannot connect to OMERO.AccessException
- Cannot access data.public ExceptionHandler<T> handleOMEROException(String message) throws ServiceException, AccessException
AccessException
if DSAccessException
was caughtServiceException
if DSOutOfServiceException
was caughtServerError
was caught (see handleOMEROException(java.lang.Throwable, java.lang.String)
)message
- Error message.AccessException
- Cannot access data.ServiceException
- Cannot connect to OMERO.public void rethrow()
public T get()
Copyright © 2020–2023 GReD. All rights reserved.