Interface ExceptionMapper
-
- All Superinterfaces:
Function<Exception,RuntimeException>
public interface ExceptionMapper extends Function<Exception,RuntimeException>
Interface to help create mapper function for exception wrapping.- Since:
- 2.0.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <E extends Exception>
ExceptionMapperforException(Class<E> clazz, Function<E,RuntimeException> mapper)
Helper method to create exception wrapper that check the exception class.static <E extends Exception>
ExceptionMapperforException(Class<E> clazz, Function<E,RuntimeException> mapper, int order)
Helper method to create exception wrapper that check the exception class.static Function<Exception,RuntimeException>
forExceptions(ExceptionMapper... mappers)
Helper method to create exception wrapper that use the first one that is applicable.static Function<Exception,RuntimeException>
forExceptions(ExceptionMapper mapper1, ExceptionMapper mapper2)
Helper method to create exception wrapper to use the first mapper if applicable or else the second.static Function<Exception,RuntimeException>
forExceptions(ExceptionMapper mapper1, ExceptionMapper mapper2, ExceptionMapper mapper3)
Helper method to create exception wrapper to use the first mapper if applicable or else the second or else the thirdstatic Function<Exception,RuntimeException>
forOrderedExceptions(Collection<ExceptionMapper> mappers)
Helper method to create exception wrapper that use the first one that is applicable, but having them sorted using theorder()
method.static ExceptionMapper
jaxbExceptionMapper()
Exception wrapper, that may be used to copy jaxb information to theWrappedException
message.default int
order()
This method is used when ExceptionMapper are registered as default Mapper to defines the right order to select then.static ExceptionMapper
saxExceptionMapper()
Exception wrapper, that may be used to copy sax information to theWrappedException
message.static ExceptionMapper
sqlExceptionMapper()
Exception wrapper, that may be used to copy error code and sql state to theWrappedException
message.Class<? extends Exception>
targetException()
static ExceptionMapper
transformerExceptionMapper()
Exception wrapper, that may be used to copy transformer exception information to theWrappedException
message.
-
-
-
Method Detail
-
sqlExceptionMapper
static ExceptionMapper sqlExceptionMapper()
Exception wrapper, that may be used to copy error code and sql state to theWrappedException
message.This mapper will only works correctly if the module java.sql is available.
- Returns:
- the Mapper for
SQLException
. - Throws:
NoClassDefFoundError
- In case theSQLException
is not available (java.sql module missing).
-
jaxbExceptionMapper
static ExceptionMapper jaxbExceptionMapper()
Exception wrapper, that may be used to copy jaxb information to theWrappedException
message.This mapper will only works correctly if the class JAXBException is available.
- Returns:
- the Mapper for
JAXBException
. - Throws:
NoClassDefFoundError
- In case theJAXBException
is not available.- Since:
- 2.1.0
-
saxExceptionMapper
static ExceptionMapper saxExceptionMapper()
Exception wrapper, that may be used to copy sax information to theWrappedException
message.This mapper will only works correctly if the class SAXException is available.
- Returns:
- the Mapper for
SAXException
. - Throws:
NoClassDefFoundError
- In case theSAXException
is not available (java.xml module missing).- Since:
- 2.1.0
-
transformerExceptionMapper
static ExceptionMapper transformerExceptionMapper()
Exception wrapper, that may be used to copy transformer exception information to theWrappedException
message.This mapper will only works correctly if the class SAXException is available.
- Returns:
- the Mapper for
TransformerException
. - Throws:
NoClassDefFoundError
- In case theTransformerException
is not available (java.xml module missing).- Since:
- 2.1.0
-
targetException
Class<? extends Exception> targetException()
-
order
default int order()
This method is used when ExceptionMapper are registered as default Mapper to defines the right order to select then.- Returns:
- an ordering key, by default 0.
- Since:
- 2.2.0
-
forException
static <E extends Exception> ExceptionMapper forException(Class<E> clazz, Function<E,RuntimeException> mapper)
Helper method to create exception wrapper that check the exception class.- Type Parameters:
E
- the type of the exception.- Parameters:
clazz
- the class of the exception to be wrapped.mapper
- the exception mapper.- Returns:
- A new exception mapper, which use the one received as parameter or
for the other exception just create a
WrappedException
.
-
forException
static <E extends Exception> ExceptionMapper forException(Class<E> clazz, Function<E,RuntimeException> mapper, int order)
Helper method to create exception wrapper that check the exception class.- Type Parameters:
E
- the type of the exception.- Parameters:
clazz
- the class of the exception to be wrapped.mapper
- the exception mapper.order
- the order- Returns:
- A new exception mapper, which use the one received as parameter or
for the other exception just create a
WrappedException
. - Since:
- 2.2.0
-
forExceptions
static Function<Exception,RuntimeException> forExceptions(ExceptionMapper mapper1, ExceptionMapper mapper2)
Helper method to create exception wrapper to use the first mapper if applicable or else the second.- Parameters:
mapper1
- the first mapper to be used.mapper2
- the second mapper to used.- Returns:
- the mapping function.
-
forExceptions
static Function<Exception,RuntimeException> forExceptions(ExceptionMapper mapper1, ExceptionMapper mapper2, ExceptionMapper mapper3)
Helper method to create exception wrapper to use the first mapper if applicable or else the second or else the third- Parameters:
mapper1
- the first mapper to be used.mapper2
- the second mapper to used.mapper3
- the third mapper to used.- Returns:
- the mapping function.
-
forExceptions
static Function<Exception,RuntimeException> forExceptions(ExceptionMapper... mappers)
Helper method to create exception wrapper that use the first one that is applicable.- Parameters:
mappers
- the mapper to be tried- Returns:
- the mapping function.
-
forOrderedExceptions
static Function<Exception,RuntimeException> forOrderedExceptions(Collection<ExceptionMapper> mappers)
Helper method to create exception wrapper that use the first one that is applicable, but having them sorted using theorder()
method.- Parameters:
mappers
- the mapper to be tried- Returns:
- the mapping function.
- Since:
- 2.2.0
-
-