The try statement for handling exceptions
File file; /* defines file to be object of class File */
- /*The body of the try statement is executed until an error occurs. It then skips to the body of the catch. */
- try{
- file = new File("filenameyouwant");
- . . . . .
- file.write("stuff put out");
- } catch (IOException e) {
- // This catches ALL I/O errors including read and write stuff
- /* Handle Exception somehow */ }
- return;
- }
- /* but the optional finally clause will be executed
- whether or not code terminates normally */
- finally
- { file.close(); }