35 ms·
Java's type system is actually unsound if you include checked exceptions as part of the type system. By using generics, you can write ExceptionUtils.rethrow[1]
by slaymaker1907 6y ago
Java's type system is actually unsound if you include checked exceptions as part of the type system. By using generics, you can write ExceptionUtils.rethrow[1] in Java[2]. I think that this should count as true type unsoundness because unlike type casts, you aren't relying on some explicit runtime check and because checked exceptions are essentially a subset algebraic effects. In practice, rethrow can be convenient if you are already catching everything anyway or if some library is overusing checked exceptions.
[1]: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/exception/ExceptionUtils.html#rethrow-java.lang.Throwable- https://commons.apache.org/proper/commons-lang/apidocs/org/a...
[2]: https://www.baeldung.com/java-sneaky-throws#:~:text=In%20Java,%20the%20sn%20eaky%20throw%20concept%20allows,effectively%20imitating%20the%20characteristics%20of%20a%20runtime%20exception https://www.baeldung.com/java-sneaky-throws#:~:text=In%20Jav....