我尝试第一次尝试catch块,并且我想让catch {}块,所以如果它捕获到异常,它将返回到原始try {}块直到用户传入的值有效。Java:初学者异常处理问题
说我有下面的代码:
try{
number=keyboard.nextInt();
}
catch(InputMismatchException e){
System.out.println("That is not an integer!");
}
编辑:
我加了一个while循环四周,劝整个事情,所以现在我有以下几点:
boolean check=true;
while(check){
try{
System.out.println("hey");
number=keyboard.nextInt();
check=false;
}
catch(InputMismatchException e){
System.out.println("That is not an integer!");
}
}
当我传入扫描仪键盘的错误值时,由于某种原因,我现在正在出现无限循环。它每次都进入try,但它不会每次调用nextInt()方法。有人知道为什么
好的......说你有以下代码......然后呢? – Daedalus 2013-03-27 20:13:00
你的问题是什么?请说明你的问题! – boomz 2013-03-27 20:15:26