package example6_2; import java.util.Scanner; public class HelpingHelper { // don't throw it, handle it! public static void main(String[] args) /* throws Exception */ { Scanner in = new Scanner(System.in); double usefulInfo = 0; while(usefulInfo <= 0) { try { usefulInfo = obtainDouble(in); System.out.println("DEBUG: succeeded with obtainDouble()"); } catch (Exception e) { System.out.println("DEBUG: Handling exception"); } System.out.println("DEBUG: end of loop"); } System.out.println("DEBUG: finished handling"); System.out.println("You entered: "+usefulInfo); } /** * * @param in * @return */ private static double obtainDouble(Scanner in) throws Exception { System.out.println("Please enter a positive double: "); double result = in.nextDouble(); if(result <= 0) { // System.out.println("I just can't take it any more!!"); throw new Exception("User entered a negative number."); } return result; } }