• 0.26.0

Logging Exceptions Thrown out of Java Methods and Swallowing Them

Annotate your methods with @Quietly annotation and every exception thrown out of the method will not be propagated, but will be logged through SLF4J:

public class Resource {
  private Object content;
  public void load(URL url) {
    this.content = url.openConnection().getContent();

If an exception occurs, it will not be thrown to the caller and it will be logged through SLF4J logging facility.

Also, take a look at @LogExceptions annotation. It does the same, but it propagates exceptions thrown to the caller.

Methods annotated with @Quietly must strictly have a void return type; otherwise, an exception will be thrown at runtime when the method is invoked. If you wish to check for non-compliant methods at compile time, you may incorporate the annotation processor QuietlyReturnTypeProcessor during your build. An example usage with maven-processor-plugin is:


The mechanism is implemented with AOP/AspectJ. Read to know how to integrate it into your pom.xml.