What does sneakyThrows buy you compared to just sticking to "extends RuntimeException" in all exception classes you create? Well, that'd be obvious:
A: Backwards compatibility, and it works in the java world. Java projects aren't (or, well, shouldn't be) limited to you and your team. You use rt.jar. You use external libraries. Most of those will not be using RuntimeExceptions. Even if for some reason everyone decided on this course of action tomorrow, there's the gigantic amount of existing libraries out there that can't just be changed on a whim. Unlike your idea of "just extend RuntimeException", sneakyThrows can be used right now and works just fine on all that code that's already out there. B: There is some value in a checked exception: It lets API users explicitly know: Hey, you need to do something with condition X, because I believe X is something you ought to be expecting, and is probably something you can handle. Your API users can then easily say: Right, but, my use case doesn't work like you think, so, I'll let it bubble up. I'm not vehemently opposed to doing away with checked exceptions either, but, trying to turn java into your personal dream language is very very different from the goal of making it better in a way that doesn't get the majority of users up in arms. Killing off checked exceptions altogether is going to lead to a pitchfork brigade. sneakyThrows probably won't; it's a compromise. Besides, I'm not entirely convinced the notion of a checked exception is worthless. I'm merely convinced that the rigidity that java confers to them is now conclusively proven to be a failed experiment. Let's try taking it down a notch before abandoning the entire concept altogether. On Sep 24, 4:17 pm, Josh Berry <[email protected]> wrote: > Simply put. What does your sneaky throws give me that I do not already have > if I am only using RuntimeExceptions? I can currently add those to my > hearts content on my method signatures. I can already catch them where they > don't appear to originate from. Warnings would be nice, I'll give. I'll > even grant that the suppression syntax can look exactly like > "SneakyThrows." > > My point is still simply that you get there pretty much all the way, by > simply using non-checked exceptions. -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
