Hi,
The try/catch statement encloses some code and is used to handle errors and exceptions that might occur in that code. The general syntax of an try and catch block is as follows:
Code:
try {
body-code
} catch (exception-classname variable-name) {
handler-code
}
For more particle example see the code below.
Code:
String fn = "/nosuchdir/myfn";
try {
// Create the file
new File(fn).createNewFile();
} catch (IOException e) {
// Print out the exception that occurred
System.out.println("Unable to create "+fn+": "+e.getMessage());
}
// Execution continues here after the IOException handler is executed
This may help you understand the basis of try and catch block
Bookmarks