System.out.println("Enter floor: ");
int f=x.nextInt();
p.setFloor(f);
This code is associated with an object
public void setFloor(int floor){
try{
this.floor = floor ;
}catch (InputMismatchException e){
System.out.println("Enter only digits");
}
}
Output
Enter floor:
hesdd
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
Why is the catch not working?