Kurt Van Etten wrote:Can I add to Vivek's question? This is something I've been wondering about too. For some of the IO classes, the close() method can throw an exception. However, putting another try/catch block inside the finally block, or nesting try/catch/finally blocks in some other way, seems awkward. What is the preferred way of handling this situation?
I prefer to have only one source of try/catch in each method. Then I logically order them so that they either can take care of the Exception or throw it to the calling method to handle.
A typical such construction is when handling files. I have a method that handles the opening of the file and returns the File-instance if it is opened. If I get a File (sometimes I check for not null and sometimes I use an Exception, depends on that assignment) then I start the reading process. If the result from the reading is OK, then I go ahead and close the file. It might be a bit overkill and I have had quite some discussions about "duplicate code, since they throw the same exception", but it helps in the debugging when several calls in a call chain can throw the same exception.
Not a clear answer to your question...