Proposal: Automatic Resource Management
Stephen Colebourne
scolebourne at joda.org
Sat Mar 7 11:04:24 PST 2009
Joshua Bloch wrote:
> On Sat, Mar 7, 2009 at 10:21 AM, Neal Gafter <neal at gafter.com> wrote:
>> I don't see how that solves the problem. Are you suggesting that
>> everywhere someone handles an exception they should also check for a
>> chain of ignored exceptions and log them?
>
> I am not suggesting this. Most people have no need to look at these
> exceptions. Those who do can read them by calling the
> getSuppressedExceptions()method.
Most of the time, there are no exceptions in closing. Sometimes there
are. And of those, just a few we care about. So its a small %age. Thus,
we shouldn't necessarily worry too much about it.
The proposal does allows the supressed exceptions to be checked immediately:
try (Writer w = open()) {
// process
} catch (IOException ex) {
if (ex.getSuppressedExceptions() > 0) {
// handle exceptions
}
}
which is pretty neat.
> If people think it's worth it, the stack
> trace printing code could be modified to include suppressed exceptions. In
> many cases, that would cause suppressed exceptions to be logged
> automatically. But I have some misgivings about this approach: I suspect
> there are programs that parse stack traces. While I frown on this behavior,
> and the spec does not guarantee that it works, I'd hate to be responsible
> for breaking these programs.
When excepion causes were added, the stack traces changed. This has
precedent and is a good idea (as it makes stack traces, the standard
debugging tool, more useful).
Stephen
More information about the coin-dev
mailing list