@Target(value={METHOD,CONSTRUCTOR}) @Retention(value=SOURCE) public @interface SneakyThrows
@SneakyThrow does not silently swallow, wrap into RuntimeException, or otherwise modify any exceptions of the listed checked exception types. The JVM does not check for the consistency of the checked exception system; javac does, and this annotation lets you opt out of its mechanism.
You should use this annotation ONLY in the following two cases:
IOException in ByteArrayOutputStreamUnsupportedEncodingException in new String(byteArray, "UTF-8").Note that, as SneakyThrow is an implementation detail and NOT part of your method signature, it is a compile time error if none of the statements in your method body can throw a listed exception.
WARNING: You must have lombok.jar available at the runtime of your app if you use SneakyThrows,
because your code is rewritten to use Lombok.sneakyThrow(Throwable).
Example:
@SneakyThrows(UnsupportedEncodingException.class)
public void utf8ToString(byte[] bytes) {
return new String(bytes, "UTF-8");
}
@SneakyThrows without a parameter defaults to allowing every checked exception.
(The default is Throwable.class).Lombok.sneakyThrow(Throwable)Copyright © 2009-2011 The Project Lombok Authors, licensed under the MIT licence.