只顯示:方法執(zhí)行了 -1,沒有提示說“循環(huán)拋出異常”?
public class TryCatchText {
public static void main(String[] args) {
TryCatchText tct =new TryCatchText();
int result =tct.text();
System.out.println("方法執(zhí)行了"+result);
}
public int text(){
int diveder =10;
int result =100;
try{
while (diveder>-1){
diveder--;
result =diveder + result/10;
}
return result;
}catch(Exception e){
e.printStackTrace();
System.out.println("循環(huán)拋出異常了");
return -1;
}
}
}
2016-10-27
自己剛才弄懂了。浪費了一次提問機會。嗚嗚