The Java Program: Pre.java

  1 // Pre.java -- try/catch statement and predefined exceptions
  2 
  3 public class Pre {
  4 
  5     public static void main (String argv[]) {
  6 
  7         try {
  8 
  9             double d = Double.valueOf(argv[0]).doubleValue();
 10 
 11             /*  Correctly formated, but extreme values are set to
 12                 ±Infinite by "valueOf".  Numbers that are very
 13                 close to zero are set to ±0.0. */
 14                 
 15             System.out.println (d);
 16 
 17         } catch (ArrayIndexOutOfBoundsException e) {
 18 
 19             System.out.println ("An argument is required.");
 20             return;
 21 
 22         } catch (NumberFormatException e) {
 23 
 24             System.out.println ("The argument must be a real number.");
 25             return;
 26 
 27         }
 28 
 29     }
 30 }