Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jvm

nio

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?

like image 791
30thh Avatar asked Oct 04 '19 08:10

30thh


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.

like image 137
apangin Avatar answered Oct 05 '22 15:10

apangin