Proposal: Automatic Resource Management
peter.levart at gmail.com
Thu Apr 2 07:33:49 PDT 2009
I apologise! The code snipped submitted by Bob Lee is not flawed at all as I
have suggested in my previous message. I did not read ARM specification
Nevertheless with increasing number of resources managed by a single ARM
construct, the track of which method has thrown exception and why is lost.
This is also true if to many statements that can throw the same exception
are written in a single try block.
Ideally all thrown exceptions should be individually accessible together
within a single block (being catch or finally block I don't know which).
This way any additional logic can act on the whole failure context.
So in this respect my proposed construct is no better because it separates
exception thrown in initialization and try block from exceptions thrown in
clean-up code which are accessible in finally block.
I understand that sometimes one just wants to be passed a single variable
that holds the "most meaningful" exception thrown among several and that is
what ARM proposal is trying to solve. A programmer using ARM construct will
have to evaluate whether ARM is the correct tool for the particular problem
and not blindly accept it because it is the correct tool for most problems
(and it is so easy to use).
On the other hand the try-catch-finally statement as we have now in Java is
always the right tool (if used correctly) but it unfortunately can too
easily be used incorrectly.
More information about the coin-dev