DEV Community


Discussion on: Hide Checked Exceptions with SneakyThrows

michelemauro profile image

Worthy subject. There still is a lot of space for debate, and different codebases will need very different solutions.
Time ago I had a coworker who introduced some SneakyThrows use, but ultimately we felt it hindred debugging because sometimes an Exception was swallowed without a trace in the logs, and at development time it promoted an habit to check a method implementation for "sneakiness"...
The definitive solution to this problem is only the Either monad at API level. Everything else is just impedence adaptation.

victorrentea profile image
Victor Rentea Author

Either (or vavr.Try) might be overkill to add everywhere for large codebases. It actually depends: if you are integrating with a system/library that throws a lot of checked exceptions at you, @SneakyThrows might not be a bad idea. On the other hand, using it just a few places it might indeed increase the risk, as people will probably be unaware of what it does and its hidden quirks.