I'd say the problem with IOException is not that it should have been unchecked, but that it's permeated I/O API in a way that painted with too broad a brush. There are calls that should throw checked exceptions and others that should throw unchecked exceptions. The way I would decide which I/O API should throw what kind of exception is as follows: if the call is likely following at least one other interaction with the underlying resource, the exception should be unchecked; but if it's likely the first call to the resource, it should be a checked exception. To illustrate this point, if we're opening a stream on a file, we know nothing about the state of the file, so we may very well have a problem that needs to be explicitly addressed. But having opened said stream successfully, writing/reading and closing are things that are extremely unlikely to fail. And if they did, the programmer is in the best possible position to decide whether this thing should be bubbled up to the top or if it can be recovered from.
Similar principles can be devised for other kinds of API. The problem with checked exceptions in Java is not that their very presence, but their application in standard libraries. Alexey ________________________________ From: Josh Berry <[email protected]> To: [email protected] Sent: Thu, March 24, 2011 1:23:26 PM Subject: Re: [The Java Posse] How to deal with CheckedExceptions 2011/3/24 Cédric Beust ♔ <[email protected]>: > Absolutely. I think all the people who think that checked exceptions are a > "failed experiment" or a "total failure" would probably think very > differently if IOException and SQLException were runtime exceptions. In such > a world, runtime exceptions would be much more frequent in Java code bases > and, as a consequence, we would probably only see checked exceptions in > places where they are really justified, thereby magnifying their usefulness. Again, name a SINGLE checked exception that everyone agrees should be checked. -- 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. -- 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.
