0

I tried Oracle's TextFieldDemo.java example. Initially I did not have file "content.txt" in the correct folder, and the Demo bombed with a StackTrace. Ugly. But the file read code does have try-catch for IOException:

InputStream in = getClass().getResourceAsStream("content.txt");
try {
    textArea.read(new InputStreamReader(in), null);
} catch (IOException e) {
    e.printStackTrace();
}

So, I changed 'e.printStackTrace()' to 'System.out.println("Cannot find file");' and still got the StackTrace.

So, I changed 'IOException' to 'Exception', and the program ended gracefully with my message.

Is Oracle's TFDemo catching the wrong exception?

KeyLawson
  • 1
  • 4

0 Answers0