Package lombok

Annotation Type SneakyThrows


@Target({METHOD,CONSTRUCTOR})
@Retention(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.

Complete documentation is found at the project lombok features page for @SneakyThrows.

Example:

 @SneakyThrows(UnsupportedEncodingException.class)
 public void utf8ToString(byte[] bytes) {
     return new String(bytes, "UTF-8");
 }
 
Becomes:
 public void utf8ToString(byte[] bytes) {
     try {
         return new String(bytes, "UTF-8");
     } catch (UnsupportedEncodingException $uniqueName) {
         throw useMagicTrickeryToHideThisFromTheCompiler($uniqueName);
         // This trickery involves a bytecode transformer run automatically during the final stages of compilation;
         // there is no runtime dependency on lombok.
     }
 
  • Optional Element Summary

    Optional Elements 
    Modifier and Type Optional Element Description
    java.lang.Class<? extends java.lang.Throwable>[] value  
  • Element Details

    • value

      java.lang.Class<? extends java.lang.Throwable>[] value
      Returns:
      The exception type(s) you want to sneakily throw onward.
      Default:
      {java.lang.Throwable.class}