/* PropogateException.java        Authors: Koffman & Wolz
 * Demonstrates exception propogation.
 * Uses Swing.
 */
import javax.swing.JOptionPane;

public class PropogateException {

  // postcondition: Returns int value of a numeric data string.
  //   Throws an exception if string is not numeric.
  public static int getDepend() throws NumberFormatException {
     String numStr = 
               JOptionPane.showInputDialog("Number of dependents:");
     return Integer.parseInt(numStr);
  }

 
  // postcondition: Calls getDepend() and handles its exceptions.
  public static void main(String[] args) {

    int children = 1;     // problem input, default is 1
    try {
       children = getDepend();
    }
    catch (NumberFormatException ex) {
       // Handle number format exception.
       JOptionPane.showMessageDialog(null,
                "Invalid integer - default is 1",
                "Error", JOptionPane.ERROR_MESSAGE);
       ex.printStackTrace();
    }
  }
}
/*
import javax.swing.JOptionPane;

public class PropogateException {

  // postcondition: Returns integer value of a numeric data string.
  //   Throws an exception if string is not numeric.
  public static int getDepend() throws NumberFormatException {
     String numStr = 
               JOptionPane.showInputDialog("Number of dependents:");
     return Integer.parseInt(numStr);
  }
 
 
  public static void main(String[] args) {

    int children = 1;     // problem input, default is 1
    try {
       children = getDepend();
    }
    catch (NumberFormatException ex) {
       // Handle number format exception.
       JOptionPane.showMessageDialog(null,
                "Invalid integer - default is 1",
                "Error", JOptionPane.ERROR_MESSAGE);
       ex.printStackTrace();
    }
  }
}
*/
