|
Lombok - v0.10.8 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Target(value={METHOD,CONSTRUCTOR})
@Retention(value=SOURCE)
public @interface SneakyThrows@SneakyThrow will avoid javac's insistence that you either catch or throw onward any checked exceptions that statements in your method body declare they generate.
@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)| Optional Element Summary | |
|---|---|
Class<? extends Throwable>[] |
value
The exception type(s) you want to sneakily throw onward. |
public abstract Class<? extends Throwable>[] value
|
Lombok - v0.10.8 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||