Skip to content

Instantly share code, notes, and snippets.

@ejknapp
Created January 20, 2010 22:31
Show Gist options
  • Select an option

  • Save ejknapp/282360 to your computer and use it in GitHub Desktop.

Select an option

Save ejknapp/282360 to your computer and use it in GitHub Desktop.
// Exception demo
package java112.labs1;
import java.io.*;
import java.util.*;
/**
* @author Eric Knapp
* class ExceptionDemo
* TODO: comment
*/
public class ExceptionDemo {
private BufferedReader input;
public void run() {
try {
input = new BufferedReader(new FileReader("sample.txt"));
System.out.println("I'm after the FileReader");
} catch (java.io.FileNotFoundException fnfe) {
System.out.println("Error");
fnfe.printStackTrace();
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("In finally");
try {
if (input != null){
input.close();
}
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
}
}
System.out.println("I'm at the end");
}
public static void main(String[] args) {
ExceptionDemo demo = new ExceptionDemo();
demo.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment