On Thu, Sep 1, 2011 at 5:56 AM, Jukka Zitting <[email protected]> wrote:
> Hi,
>
> On Thu, Sep 1, 2011 at 11:36 AM, Michael McCandless
> <[email protected]> wrote:
>> While rare for IS.close() to throw an exception, if it does, it's
>> quite awful because it masks the original exception.  It seems best to
>> be defensive?
>
> With closeQuietly() you'd really be throwing information out in case
> where close() fails when no other exception has been thrown. Instead
> of one exception masking another, you'd have no exceptions masking
> one!

Duh, you're right: we don't want to use closeQuietly if there was no exception.

For Lucene we do this:

  // open something
  boolean success = false;
  try {
     // do something
    success = true;
  } finally {
    if (!success) {
      closeQuietly();
    } else {
      closeNormally();
    }
  }

This gets cleaner with Java 7 but it's some ways away before Tika can
require Java 7...

Mike

Reply via email to