Skippy is a Java library for easy exception transforming into detailed messages by annotating classes and methods.
Use the maven.
<dependency>
<groupId>com.jarslab.skippy</groupId>
<artifactId>skippy-spi</artifactId>
<version>1.0-RC</version>
</dependency>
@ExceptionMapping(exceptions = Exception.class, errorDetails = OverallErrorDetails.class)
private class SuspiciousClass
{
@ExceptionMapping(exceptions = IllegalStateException.class,
errorDetails = IllegalStateErrorDetails.class)
public void suspiciousMethod()
{
...
}
}
final ClassExceptionMapperProvider mapperProvider =
new ClassExceptionMapperProvider(SuspiciousClass.class);
try {
suspiciousClass.suspiciousMethod()
} catch (Exception e) {
final ExceptionMapper mapper =
mapperProvider.getMapper(SuspiciousClass.class.getMethod("notAnnotatedMethod"));
final boolean mappable = mapper.test(exception);
if (mappable) {
final ErrorDetails errorDetails = mapper.apply(exception);
}
}