title: Best way to exit a program when I want an exception to be thrown?
body: <p>I'm writing a Java program that reads in a file of words. The program crucially depends on this file, so I really do want the program to end if for whatever reason there's an IOException when reading the file.</p>
  
  <p>What's the best way to end the program? I think I'm forced to surround my file-reading inside a try/catch block, so should I add a <code>System.exit(0)</code> inside my catch? For example, should I do something like the following?</p>
  
  <pre><code>try {
    BufferedReader br = new BufferedReader(new FileReader("myfile.txt"));
    String line;
    while ((line = br.readLine()) != null) {
      // process...
    }
  } catch(IOException e) {
    System.out.println("Error: " + e);
    System.exit(0); // ???
  }
  </code></pre>