when to use try...catch
When coding, there are some statements that need try .. catch block otherwise complier gives error and forces the coder to write such statements under try ... catch block.
How can I know, which statements should be written under try...catch block:confused:
Currently, when complier gives error, I then put that statement under try...catch.
That seems to be the general practice - add the try-catch blocks where indicated by the compiler. The javadocs is/are the place to find out what is required, viz, the Method Detail section for the method(s) in question.
Thanks. Got the idea.
I checked Java Docs and found following signature for FileOutStream constructor:
which means we have to write in under try...catch block.
public FileOutputStream(File file)