Results 1 to 3 of 3
  1. #1
    Agathorn is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default unreported exception IOException -- Yet I AM catching it?

    Hey all, I'm an experienced programmer but new to Java. Decided to try writing a small utility in Java so it would be cross-platform without much extra work :)

    I'm having some trouble though with some code that I pretty much pulled directly out of Sun's documentation.

    Java Code:
        public void ListFolder()
        {
                DirectoryStream<Path> stream = null;
                try {
                    stream = wFolder.newDirectoryStream();
                    for (Path file: stream) 
                    {
                        System.out.println(file.getName());
                    }
                } catch (IOException e) {
                    System.err.println(e);
                } finally {
                    if (stream != null) stream.close();
                }
        }
    The compiler keeps reporting "Unreported exception IOException; must be caught or declared to be thrown", yet that is exactly what I thought I was doing in the code above.

    I am importing java.io.IOException

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    Java Code:
    } finally {
        if (stream != null) stream.close();
    }
    I think you need to try/catch this. Closable throws IOException
    Last edited by mrmatt1111; 09-18-2009 at 11:18 PM.
    My Hobby Project: LegacyClone

  3. #3
    Agathorn is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default

    Thank you very much mrmat1111

    That does indeed seem to fix it. Gosh these try/catch blocks can get confusing! Makes me want to crawl back to C.

    Anyway it works now. Wonder if there is a way to send a note to Sun that their docs are a bit off...

Similar Threads

  1. synchronization kid riding a swing n catching breath
    By jodeen20 in forum Threads and Synchronization
    Replies: 2
    Last Post: 09-10-2008, 01:46 PM
  2. Error: unreported exception java.io.IOException; ??
    By jonsamwell in forum New To Java
    Replies: 5
    Last Post: 08-24-2008, 04:11 AM
  3. GUI IOException
    By serfster in forum New To Java
    Replies: 3
    Last Post: 06-13-2008, 04:19 AM
  4. Swing - catching click button event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:03 PM
  5. AWT - catching click button event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •