Lombok @SneakyThrows Annotation

@SneakyThrows can be used to sneakily throw checked exceptions without actually declaring this in your method’s throws clause. This somewhat contentious ability should be used carefully, of course. The code generated by lombok will not ignore, wrap, replace, or otherwise modify the thrown checked exception; it simply fakes out the compiler. On the JVM (class file) level, all exceptions, checked or not, can be thrown regardless of the throws clause of your methods, which is why this works.

 

public class DefaultClone implements Cloneable {    @Override    protected Object clone() throws CloneNotSupportedException {        return super.clone();    }}

Solution with Try catch Block

public class DefaultClone2 implements Cloneable {    @Override    protected Object clone() {        try {            return super.clone();        } catch (CloneNotSupportedException e) {            throw new RuntimeException(e);        }    }}

Solution with Lombok @SneakyThrows Annotation

import lombok.SneakyThrows;public class SneakyClone implements Cloneable {    @SneakyThrows    @Override    protected Object clone() {        return super.clone();    }}

What happened behind:

public class SneakyClone implements Cloneable {    @Override    protected Object clone() {        try {            return super.clone();        } catch (final java.lang.Throwable $ex) {            throw lombok.Lombok.sneakyThrow($ex);        }    }}