/** * COSC 1010 Exception Demo. * @author Dennis Brylow * @version 1.0,   2010 Nov 15 */ import java.util.Scanner; public class ExcpTest { public static void main(String[] args) throws Exception { Scanner keyboard = new Scanner(System.in); int x = 0; try { x = keyboard.nextInt(); } catch (java.util.InputMismatchException ime) { System.err.println("Got something that wasn't a number!"); System.err.println("Exception was: " + ime); x = -1; } catch (java.util.NoSuchElementException nsee) { System.err.println("No input!"); x = -2; } catch (Exception e) { System.err.println("Unknown problem! " + e); } if (x == 13) { throw new Exception("Entered 13. That is forbidden."); } System.out.println(x); } }