[Solved] Creating custom java exception [duplicate]

This should help you for scanning Integer values. try{ System.out.print(“Enter an integer: “); int number = input.nextInt(); } catch (InputMismatchException ex) { System.out.println(“Incorrect input: an integer is required)”); //It’s also possible to throw your custom Exception here, like “throw new CustomException();” } About the IndexOutOfBoundsException, just write a try catch block around the area, where … Read more