From 28f0c4c4b042a47fc2ee3323d3b8d90329991426 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 30 Jan 2020 17:24:37 +0100 Subject: [website] added a line about how sneakythrows doesn't really help you much with lambdas; a common question. --- website/templates/features/SneakyThrows.html | 2 ++ 1 file changed, 2 insertions(+) (limited to 'website') diff --git a/website/templates/features/SneakyThrows.html b/website/templates/features/SneakyThrows.html index 5a2d5bbd..5f5c06df 100644 --- a/website/templates/features/SneakyThrows.html +++ b/website/templates/features/SneakyThrows.html @@ -13,6 +13,8 @@ An 'impossible' exception. For example, new String(someByteArray, "UTF-8"); declares that it can throw an UnsupportedEncodingException but according to the JVM specification, UTF-8 must always be available. An UnsupportedEncodingException here is about as likely as a ClassNotFoundError when you use a String object, and you don't catch those either! +

+ Being constrained by needlessly strict interfaces is particularly common when using lambda syntax (arg -> action); however, lambdas cannot be annotated, which means it is not so easy to use @SneakyThrows in combination with lambdas.

Be aware that it is impossible 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 @SneakyThrows mechanism without some deliberation!

-- cgit