I can't figure out why my getHours() is catching InputMismatchException when I have only thrown InvalidHrExcep to the method itself. Can anyone enlighten me?
public static void main (String [] args)
{
do
{
try
{
getHours();
getAmPm();
accept = true;
}
catch(InvalidHrExcep h)
{
System.out.println (h);
accept = false;
console.nextLine();
}
catch (InputMismatchException e)
{
System.out.println (e);
System.out.println("Input must be AM or PM.");
accept = false;
console.nextLine();
}
}while(accept == false);
}
My method for getHours()
public static int getHours() throws InvalidHrExcep
{
System.out.print ("Enter hours: ");
int hour = console.nextInt();
if(hour > 0 && hour <= 12)
{
return hour;
}
else
{
throw new InvalidHrExcep();
}
}