mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 12:19:00 +00:00
[website] added a line about how sneakythrows doesn't really help you much with lambdas; a common question.
This commit is contained in:
1 file changed
+2
@@ -13,6 +13,8 @@
|
||||
An 'impossible' exception. For example, <code>new String(someByteArray, "UTF-8");</code> declares that it can throw an <code>UnsupportedEncodingException</code> but according to the JVM specification, UTF-8 <em>must</em> always be available. An <code>UnsupportedEncodingException</code> here is about as likely as a <code>ClassNotFoundError</code> when you use a String object, and you don't catch those either!
|
||||
</li>
|
||||
</ul>
|
||||
</p><p>
|
||||
Being constrained by needlessly strict interfaces is particularly common when using lambda syntax (<code>arg -> action</code>); however, lambdas cannot be annotated, which means it is not so easy to use <code>@SneakyThrows</code> in combination with lambdas.
|
||||
</p><p>
|
||||
Be aware that it is <em>impossible</em> to catch sneakily thrown checked types directly, as javac will not let you write a catch block for an exception type that no method call in the try body declares as thrown. This problem is not relevant in either of the use cases listed above, so let this serve as a warning that you should not use the <code>@SneakyThrows</code> mechanism without some deliberation!
|
||||
</p><p>
|
||||
|
||||
Reference in new issue
Block a user