class SquareRoot2 { public static void main(String[] args) { try { double number = Double.valueOf(args[0]).doubleValue(); double root = compute(number); System.out.println( "The square root of " + number + " is " + root); } catch (ArrayIndexOutOfBoundsException e) { System.out.println( "Please supply a command-line argument"); } catch (NumberFormatException e) { System.out.println( "The command-line argument must be a number"); } } static double compute(double number) { return Math.sqrt(number); } }
ImaginaryNumberException
compute()
compute
main()