6 Replies Latest reply: Feb 28, 2013 7:32 AM by gimbal2 RSS

    java.nio.file.NoSuchFileException on WatchService

    358893
      Hi,

      I am testing a program using Java 7 WatchService to watch a directory and get an error:

      java.nio.file.NoSuchFileException: /media/C852-8B2A
      java.nio.file.NoSuchFileException: /media/C852-8B2A
           at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
           at sun.nio.fs.UnixException.asIOException(UnixException.java:111)
           at sun.nio.fs.LinuxWatchService$Poller.implRegister(LinuxWatchService.java:243)
           at sun.nio.fs.AbstractPoller.processRequests(AbstractPoller.java:260)
           at sun.nio.fs.LinuxWatchService$Poller.run(LinuxWatchService.java:326)
           at java.lang.Thread.run(Thread.java:722)

      this exception shows on Ubuntu, but not on Windows.
      The exception was correct: the directory was gone. But this exception shows on the console. I would like to catch it. How to catch this exception in my application?

      Any information would be appreciated. Thanks in advance.
        • 1. Re: java.nio.file.NoSuchFileException on WatchService
          rp0428
          We cannot debug code that we cannot see.

          So try the example from the Java Tutorial and see if it works the way you expect.
          http://docs.oracle.com/javase/tutorial/essential/io/notification.html
          • 2. Re: java.nio.file.NoSuchFileException on WatchService
            358893
            There is no bug. The directory was gone. The exception is correct. My program runs as expected.
            My question is: I do not want the error be on the console. I would like to catch it. But I do not know how to catch it. Is there a way to access the thread?

            Edited by: _w**** on Feb 27, 2013 7:29 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
            • 3. Re: java.nio.file.NoSuchFileException on WatchService
              rp0428
              We cannot debug code that we cannot see.
              • 4. Re: java.nio.file.NoSuchFileException on WatchService
                jtahlborn
                rp0428 wrote:
                We cannot debug code that we cannot see.
                i believe the code the OP is referring to is within the jdk. looking at the LinuxWatchService, it looks like the handling of the FileNotFoundException is outside of the user's control. the exception is thrown and caught in a utility Thread run by the LinuxWatchService, which prints the exception using Throwable.printStackTrace(). yuck.
                • 5. Re: java.nio.file.NoSuchFileException on WatchService
                  jtahlborn
                  deleting, web browser double post.
                  • 6. Re: java.nio.file.NoSuchFileException on WatchService
                    gimbal2
                    jtahlborn wrote:
                    i believe the code the OP is referring to is within the jdk. looking at the LinuxWatchService, it looks like the handling of the FileNotFoundException is outside of the user's control. the exception is thrown and caught in a utility Thread run by the LinuxWatchService, which prints the exception using Throwable.printStackTrace(). yuck.
                    That you still find this terrible practice in JDK code in the 21st century :/
                    That you still find this terrible practice in JDK code in the 21st century :/

                    I guess you could hook it by setting your own System.err instance that does not output anything, but then you lose all System err output of course. Perhaps that is not a problem.