System.out.println("Enter floor: ");
int f=x.nextInt();
p.setFloor(f);
此代码与对象
相关联public void setFloor(int floor){
try{
this.floor = floor ;
}catch (InputMismatchException e){
System.out.println("Enter only digits");
}
}
输出
Enter floor:
hesdd
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
为什么捕获不起作用?
答案 0 :(得分:4)
Scanner.nextInt
时, const client = new AWSAppSyncClient({
url: AppSync.graphqlEndpoint,
region: AppSync.region,
auth: {
type: AUTH_TYPE.AWS_IAM,
credentials: () => Auth.currentCredentials()
},
complexObjectsCredentials: () => Auth.currentCredentials(),
});
被抛出,你立即抓住它:
InputMismatchException