Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6852033 Inputs/Outputs methods to make common I/O tasks easy to do
  3. JDK-8136428

Add Closeable:closeIgnoreException to close without throwing

    XMLWordPrintable

Details

    • Sub-task
    • Resolution: Unresolved
    • P4
    • tbd
    • 9
    • core-libs
    • None
    • Cause Known

    Description

      In many cases, it would be useful to close and not throw an exception.
      Either the Exception can be quietly ignored, or the method could return the Exception, allowing the caller to ignore it, log it, or rethrow it.
      This kind of method would allow the cleanup of many places in the JDK that go to extra lengths to handle/ignore the exception from close.

      For example,
      + /**
      + * Closes the Closable and returns the exception if one occurs.
      + *
      + * @param closeable the closable to close
      + * @return {@code null} if the close succeeded without throwing an exception.
      + * otherwise returns the IOException
      + */
      + public default IOException closeQuietly() {
      + try {
      + closeable.close();
      + } catch (IOException ie) {
      + return ie;
      + }
      + return null;
      + }

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              rriggs Roger Riggs
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: