import java.util.Scanner; import java.util.InputMismatchException; /** * This class illustrates what happens when an unchecked exception * occurs. An unchecked exception is an exception that usually cannot * be anticipated and/or recovered from. In Java, you do not have * to handle an unchecked exception. * * @author alchambers * @version sp18 */ public class UncheckedException{ /** * Trigger an unchecked exception by typing a String instead * of an integer. */ private static void runtimeException(){ System.out.println("Inside runtimeException()"); Scanner scan = new Scanner(System.in); System.out.print("How old are you? "); int age = scan.nextInt(); } /** * Calls the runtimeException() method */ private static void method2(){ System.out.println("Inside method2()"); runtimeException(); System.out.println("Inside method2()"); } /** * Calls method2() */ private static void method1(){ System.out.println("Inside method1()"); method2(); System.out.println("Inside method1()"); } public static void main(String[] args){ method1(); } }