title: Throw java exception and stops
body: <p>I have a simple Java program with a <code>main</code> method and several other methods. Each method can fail with a different exception.</p>
  
  <p>What I am doing now is adding a <code>try</code>-<code>catch</code> block for each method, but the problem is that if the first method fails and I catch and print the exception, the program proceeds.</p>
  
  <p>I want the program to stop if any exception occurs. What is the recommended way to solve this in Java?</p>
  
  <p>My current code is the following:</p>
  
  <pre><code>public static void main(String[] args) {
      // Get File Path
      String filePath = null;
      try {
          filePath = getFilePath(args);
      } catch (FileNotFoundException e) {
          System.out.println("not found");
      }
  
      // Load File content
      AtomicReference&lt;String&gt; content = new AtomicReference&lt;String&gt;();
      try {
          content.set(readYamlFile(sourceFilePath));
      } catch (IOException e) {
          System.out.println("Not able to load file");
      }
  
  
      try {
          jsonStr = convert(content.toString());
      } catch (IOException e) {
          System.out.println("Conversion failed ");
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Every method has a different exception type. Should I use some generic exception and just throw it with the appropriate message, instead of using the try catch blocks?</p>