3 ms·
The diaper pattern is a well-know anti-pattern. But the idea that all exceptions are thus evil is a giant leap of logic that is hard to swallow.
by gsmethells 10y ago
The diaper pattern is a well-know anti-pattern. But the idea that all exceptions are thus evil is a giant leap of logic that is hard to swallow.
- emsy 10y agoAt least in Java, exceptions are often very granular, when you actually don't care. Let's say you want to read a file. You may get an exception for malformed paths, permission errors, filesystem errors and so on. It's unlikely that I will recover from any of these errors during runtime. The only thing I really can do is log the error, inform the user and send a report.
- sgift 10y agoMy usual use case involves adding that file to a "retry later" queue. Just logging it and hoping for the best doesn't cut it if you really need to read the file. But maybe I'm an outlier. Most files I see have to be processed, either now or later, without any manual interaction.
- marcosdumay 10y agoVery granular, and not hierarchical enough. What is ironical for Java. Going either way would fix the problem. There's also a lack of support for them in generics. The checked exceptions problem on Java is one of overall language and libraries design, not inherent on the checked exceptions idea.
- emsy 10y agoYou're right, in fact I'd argue that checked exceptions are a very good idea. A checked exception is java's way to say: Here is a side effect, take care of it. The problem is that it can't be enforced consequently, partially because Java allows objects to be null. Otherwise checked exceptions would be akin to monads.
- wellpast 10y agoDiaper pattern - Never heard that before but I like it and it's accurate. I prefer to catch Exceptions that I know how I want to handle and handle them accordingly. For other exceptions, I prefer to let them fly. If and when they happen, I can then understand the scenario and implement the desired logic.