Generally whatever we write in the try block is actually tried to execute and if it causes some exception, then catch block comes to help but even if the try block does not throw exception, the compiler does not complain, but in my case, I want to create a directory and I am writing the code for that in try block but the compiler says something interesting as below
here is the code
and when program is compiled, then error is
F:\Java\Concepts\Strings,IO Formatting and Parsing\File IO>javac CreateFileAndDi
rectory.java
CreateFileAndDirectory.java:38: exception java.io.IOException is never thrown in
body of corresponding try statement
catch (IOException e)
^
1 error
but this does not happen in case of CreateFile() method, means it compiles fine but in case of CreateDirctury, it does not create, so I commented out the code for catch block
there is another example ,
here is simple code that compiles fine even if the try block does not throw any kind of exception
This compiler perfectly
what can be the difference?
I am finding it very very interesting
please help experts