Pull to refresh
4
0
Глеб Бондарчук @gbondarchuk2019

Software Engineer

Send message

Да, sneaky throws основан на такой фишке JVM, что когда мы бросаем generic exception (который может быть как checked, так и unchecked) — JVM не вправе рассматривать exception как checked во всех случаях, т.к. exception можеть быть unchecked.


По сути работает такая конструкция:


static <E extends Exception> void throwQuietly(Exception e) throws E {
      throw (E) e;
}

Использовать можно так:


try {
   smth that throws checked exception
} catch(Exception e) {
   throwQuietly(e);
}

В случае экспешена он будет выброшен, но обрабатывать его не нужно, даже если он checked.

Information

Rating
Does not participate
Registered
Activity

Specialization

Specialist
Senior
Java
Docker
PostgreSQL
Java Spring Framework
Hibernate
Spring Boot
MySQL
OOP
SQL
Git