Java Exception catch Throwable object

Description

Java Exception catch Throwable object

public class Main {
   //from w  w  w  .j av a 2  s.  co  m
   public static void main(String[] args) {
      int age = 30;
      int retirementFund = 10000;
      int yearsInRetirement = 0;
      String name = "David Johnson";
      for (int i = age; i <= 65; i++) {
         recalculate(retirementFund, 0.1);
      }
      try {
          double monthlyPension = retirementFund/yearsInRetirement/12;
          System.out.println(name + " will have $" + monthlyPension
              + " per month for retirement.");
      } catch (Throwable thrown){
          System.out.println(thrown);
          System.exit(0);
      }
   }

   public static void recalculate(double fundAmount, double rate) {
      fundAmount = fundAmount * (1 + rate);
   }
}



PreviousNext

Related