Basic HTML version of Foils prepared Sept 6 1998

Foil 49 The complete try/catch/finally statement

From Java Tutorial 98-2: Java Language and Object Oriented Techniques CPS606 Fall Semester 1999 -- Sept 7 1999. by Geoffrey C. Fox, Nancy McCracken


File file; /* defines file to be object of class File */
  • 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();
  • }



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Mon Sep 6 1999