Class java.nio.file.Files throws FileAlreadyExistsException as "optional specific exception". What does it mean?

Viewed 431

Does anybody know, what exactly "optional specific exception" means?

https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html

Some JVMs throw it and some not? If they don't do it, throw they a general IOException or no exception at all? It there a statistic over different implementations, how "optional" it really is?

1 Answers

From the book "Java I/O, NIO and NIO.2" by Jeff Friesen:

FileAlreadyExistsException is an example of an optional specific exception. It's optional because it's thrown when the underlying operating system can detect the specific error leading to the exception. If the error cannot be detected, its IOException ancestor is thrown instead.

Related