Package fr.igred.omero.exception
Class ExceptionHandler<T>
- java.lang.Object
-
- fr.igred.omero.exception.ExceptionHandler<T>
-
public class ExceptionHandler<T> extends 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 Throwable>
static interface
ExceptionHandler.OMEROFunction<T,R>
Interface for a function that can throw OMERO exceptions.static interface
ExceptionHandler.ThrowingConsumer<T,E extends Throwable>
static interface
ExceptionHandler.ThrowingFunction<T,R,E extends Throwable>
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExceptionHandler(T value, Exception exception)
Private class constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <I,R>
Rcall(I input, ExceptionHandler.OMEROFunction<? super I,? extends R> mapper, String message)
Calls the provided function on the given input and return the result or handles any OMERO exception and rethrows the appropriate exception with the specified message.T
get()
Returns the contained object.ExceptionHandler<T>
handleException(String message)
Deprecated.Throws:AccessException
ifDSAccessException
was caughtServiceException
ifDSOutOfServiceException
was caught The appropriate exception ifServerError
was caught (seehandleOMEROException(java.lang.Throwable, java.lang.String)
)static void
handleException(Throwable t, String message)
Deprecated.Helper method to convert an exception from: DSAccessException to AccessException DSOutOfServiceException to ServiceException ServerError to OMEROServerErrorExceptionHandler<T>
handleOMEROException(String msg)
Throws:AccessException
ifDSAccessException
was caughtServiceException
ifDSOutOfServiceException
was caught The appropriate exception ifServerError
was caught (seehandleOMEROException(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 elseExceptionHandler<T>
handleServerAndService(String msg)
Checks if a ServerError or a DSOutOfService was thrown and handles the exception according to the cause.ExceptionHandler<T>
handleServiceOrAccess(String message)
Deprecated.Throws:ServiceException
ifDSOutOfServiceException
was caughtAccessException
ifDSAccessException
was caughtstatic void
handleServiceOrAccess(Throwable t, String message)
Deprecated.Helper method to convert an exception from: DSOutOfServiceException to ServiceException DSAccessException to AccessExceptionExceptionHandler<T>
handleServiceOrServer(String message)
Deprecated.Throws:ServiceException
ifDSOutOfServiceException
was caughtOMEROServerError
ifServerError
was caughtstatic void
handleServiceOrServer(Throwable t, 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 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>
ExceptionHandler<T>rethrow(Class<E> type)
Throws an exception from the specified type, if one was caught.<E extends Throwable,F extends Throwable>
ExceptionHandler<T>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()
-
-
-
Method Detail
-
handleServiceOrServer
@Deprecated public static void handleServiceOrServer(Throwable t, 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(Throwable t, 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(Throwable t, 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 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 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.
-
call
public static <I,R> R call(I input, ExceptionHandler.OMEROFunction<? super I,? extends R> mapper, String message) throws AccessException, ServiceException
Calls the provided function on the given input and return the result or handles any OMERO exception and rethrows the appropriate exception with the specified message.- Type Parameters:
I
- Input argument type.R
- Returned object type.- Parameters:
input
- Object to process.mapper
- Lambda to apply on object.message
- The message, if an exception is thrown.- Returns:
- The function output.
- Throws:
ServiceException
- Cannot connect to OMERO.AccessException
- Cannot access data.
-
handleOMEROException
public static void handleOMEROException(Throwable throwable, String message) throws ServiceException, AccessException
Checks the cause of an exception on OMERO and throws:-
ServiceException
if the cause was: -
AccessException
if the cause was:SecurityViolation
- Anything else
See
Facility.handleException(java.lang.Object, java.lang.Throwable, java.lang.String)
- Parameters:
throwable
- The exception.message
- Error message.- Throws:
ServiceException
- Cannot connect to OMERO.AccessException
- Cannot access data.
-
-
rethrow
public <E extends Throwable> ExceptionHandler<T> rethrow(Class<E> type) throws E extends 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 Throwable
-
rethrow
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
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 Throwable
-
handleServerAndService
public ExceptionHandler<T> handleServerAndService(String msg) throws ServiceException, AccessException
Checks if a ServerError or a DSOutOfService was thrown and handles the exception according to the cause.- Parameters:
msg
- Error message.- Returns:
- The same ExceptionHandler.
- Throws:
ServiceException
- Cannot connect to OMERO.AccessException
- Cannot access data.
-
handleServiceOrServer
@Deprecated public ExceptionHandler<T> handleServiceOrServer(String message) throws ServiceException, OMEROServerError
Deprecated.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
@Deprecated public ExceptionHandler<T> handleServiceOrAccess(String message) throws ServiceException, AccessException
Deprecated.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
@Deprecated public ExceptionHandler<T> handleException(String message) throws ServiceException, AccessException, OMEROServerError
Deprecated.Throws:AccessException
ifDSAccessException
was caughtServiceException
ifDSOutOfServiceException
was caught- The appropriate exception if
ServerError
was caught (seehandleOMEROException(java.lang.Throwable, java.lang.String)
)
- Parameters:
message
- Error message.- Returns:
- The same ExceptionHandler.
- Throws:
AccessException
- Cannot access data.OMEROServerError
- Server error.ServiceException
- Cannot connect to OMERO.
-
handleOMEROException
public ExceptionHandler<T> handleOMEROException(String msg) throws ServiceException, AccessException
Throws:AccessException
ifDSAccessException
was caughtServiceException
ifDSOutOfServiceException
was caught- The appropriate exception if
ServerError
was caught (seehandleOMEROException(java.lang.Throwable, java.lang.String)
)
- Parameters:
msg
- Error message.- Returns:
- The same ExceptionHandler.
- Throws:
AccessException
- Cannot access data.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.
-
-