Package fr.igred.omero.exception
Class ExceptionHandler<T>
- java.lang.Object
-
- fr.igred.omero.exception.ExceptionHandler<T>
-
public class ExceptionHandler<T> extends java.lang.Object
Class to handle and convert OMERO exceptions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ExceptionHandler.ExceptionWrapper<T,E extends java.lang.Throwable>
static interface
ExceptionHandler.ThrowingConsumer<T,E extends java.lang.Throwable>
static interface
ExceptionHandler.ThrowingFunction<T,R,E extends java.lang.Throwable>
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExceptionHandler(T value, java.lang.Exception exception)
Private class constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description T
get()
Returns the contained object.ExceptionHandler<T>
handleException(java.lang.String message)
Throws:AccessException
ifDSAccessException
was caughtServiceException
ifDSOutOfServiceException
was caughtOMEROServerError
ifServerError
was caughtstatic void
handleException(java.lang.Throwable t, java.lang.String message)
Deprecated.Helper method to convert an exception from: DSAccessException to AccessException DSOutOfServiceException to ServiceException ServerError to OMEROServerErrorExceptionHandler<T>
handleServiceOrAccess(java.lang.String message)
Throws:ServiceException
ifDSOutOfServiceException
was caughtAccessException
ifDSAccessException
was caughtstatic void
handleServiceOrAccess(java.lang.Throwable t, java.lang.String message)
Deprecated.Helper method to convert an exception from: DSOutOfServiceException to ServiceException DSAccessException to AccessExceptionExceptionHandler<T>
handleServiceOrServer(java.lang.String message)
Throws:ServiceException
ifDSOutOfServiceException
was caughtOMEROServerError
ifServerError
was caughtstatic void
handleServiceOrServer(java.lang.Throwable t, java.lang.String message)
Deprecated.Helper method to convert an exception from: DSOutOfServiceException to ServiceException ServerError to OMEROServerErrorstatic <I,R>
ExceptionHandler<R>of(I input, ExceptionHandler.ThrowingFunction<? super I,? extends R,? extends java.lang.Exception> mapper)
Creates an ExceptionHandler from an object and a function.static <I> ExceptionHandler<I>
ofConsumer(I input, ExceptionHandler.ThrowingConsumer<? super I,? extends java.lang.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 java.lang.Throwable>
ExceptionHandler<T>rethrow(java.lang.Class<E> type)
Throws an exception from the specified type, if one was caught.<E extends java.lang.Throwable,F extends java.lang.Throwable>
ExceptionHandler<T>rethrow(java.lang.Class<E> type, ExceptionHandler.ExceptionWrapper<? super E,? extends F> mapper, java.lang.String message)
Throws an exception converted from the specified type, if one was caught.java.lang.String
toString()
-
-
-
Constructor Detail
-
ExceptionHandler
protected ExceptionHandler(T value, java.lang.Exception exception)
Private class constructor.- Parameters:
value
- Object to process.exception
- Caught exception.
-
-
Method Detail
-
handleServiceOrServer
@Deprecated public static void handleServiceOrServer(java.lang.Throwable t, java.lang.String message) throws ServiceException, OMEROServerError
Deprecated.Helper method to convert an exception from:- DSOutOfServiceException to ServiceException
- ServerError to OMEROServerError
- Parameters:
t
- The Exceptionmessage
- Short explanation of the problem.- Throws:
ServiceException
- Cannot connect to OMERO.OMEROServerError
- Server error.
-
handleServiceOrAccess
@Deprecated public static void handleServiceOrAccess(java.lang.Throwable t, java.lang.String message) throws ServiceException, AccessException
Deprecated.Helper method to convert an exception from:- DSOutOfServiceException to ServiceException
- DSAccessException to AccessException
- Parameters:
t
- The Exceptionmessage
- Short explanation of the problem.- Throws:
ServiceException
- Cannot connect to OMERO.AccessException
- Cannot access data.
-
handleException
@Deprecated public static void handleException(java.lang.Throwable t, java.lang.String message) throws ServiceException, AccessException, OMEROServerError
Deprecated.Helper method to convert an exception from:- DSAccessException to AccessException
- DSOutOfServiceException to ServiceException
- ServerError to OMEROServerError
- Parameters:
t
- The Exceptionmessage
- Short explanation of the problem.- Throws:
AccessException
- Cannot access data.OMEROServerError
- Server error.ServiceException
- Cannot connect to OMERO.
-
of
public static <I,R> ExceptionHandler<R> of(I input, ExceptionHandler.ThrowingFunction<? super I,? extends R,? extends java.lang.Exception> mapper)
Creates an ExceptionHandler from an object and a function.- Type Parameters:
I
- Input argument type.R
- Returned object type.- Parameters:
input
- Object to process.mapper
- Lambda to apply on object.- Returns:
- ExceptionHandler wrapping the returned object.
-
ofConsumer
public static <I> ExceptionHandler<I> ofConsumer(I input, ExceptionHandler.ThrowingConsumer<? super I,? extends java.lang.Exception> consumer)
Creates an ExceptionHandler from an object and a function with no return value.- Type Parameters:
I
- Input argument type.- Parameters:
input
- Object to process.consumer
- Lambda to apply on object.- Returns:
- ExceptionHandler wrapping the object to process.
-
rethrow
public <E extends java.lang.Throwable> ExceptionHandler<T> rethrow(java.lang.Class<E> type) throws E extends java.lang.Throwable
Throws an exception from the specified type, if one was caught.- Type Parameters:
E
- The type of the exception.- Parameters:
type
- The exception class.- Returns:
- The same ExceptionHandler.
- Throws:
E
- An exception from the specified type.E extends java.lang.Throwable
-
rethrow
public <E extends java.lang.Throwable,F extends java.lang.Throwable> ExceptionHandler<T> rethrow(java.lang.Class<E> type, ExceptionHandler.ExceptionWrapper<? super E,? extends F> mapper, java.lang.String message) throws F extends java.lang.Throwable
Throws an exception converted from the specified type, if one was caught.- Type Parameters:
E
- The type of the exception.F
- The type of the exception thrown.- Parameters:
type
- The exception class.mapper
- Lambda to convert the caught exception.message
- Error message.- Returns:
- The same ExceptionHandler.
- Throws:
F
- A converted Exception.F extends java.lang.Throwable
-
handleServiceOrServer
public ExceptionHandler<T> handleServiceOrServer(java.lang.String message) throws ServiceException, OMEROServerError
Throws:ServiceException
ifDSOutOfServiceException
was caughtOMEROServerError
ifServerError
was caught
- Parameters:
message
- Error message.- Returns:
- The same ExceptionHandler.
- Throws:
ServiceException
- Cannot connect to OMERO.OMEROServerError
- Server error.
-
handleServiceOrAccess
public ExceptionHandler<T> handleServiceOrAccess(java.lang.String message) throws ServiceException, AccessException
Throws:ServiceException
ifDSOutOfServiceException
was caughtAccessException
ifDSAccessException
was caught
- Parameters:
message
- Error message.- Returns:
- The same ExceptionHandler.
- Throws:
ServiceException
- Cannot connect to OMERO.AccessException
- Cannot access data.
-
handleException
public ExceptionHandler<T> handleException(java.lang.String message) throws ServiceException, AccessException, OMEROServerError
Throws:AccessException
ifDSAccessException
was caughtServiceException
ifDSOutOfServiceException
was caughtOMEROServerError
ifServerError
was caught
- Parameters:
message
- Error message.- Returns:
- The same ExceptionHandler.
- Throws:
AccessException
- Cannot access data.OMEROServerError
- Server error.ServiceException
- Cannot connect to OMERO.
-
rethrow
public void rethrow()
Rethrows exception if one was caught (to not swallow it).
-
get
public T get()
Returns the contained object.- Returns:
- See above.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-