public KalaGame(KeyBoardPlayer player1,KeyBoardPlayer player2)
{ //super(0);
int key=0;
try
{
do{
System.out.println("Enter the number of stones to play with: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
key = Integer.parseInt(br.readLine());
if(key<0 || key>10)
throw new InvalidStartingStonesException(key);
}
while(key<0 || key>10);
player1=new KeyBoardPlayer();
player2 = new KeyBoardPlayer();
this.player1=player1;
this.player2=player2;
state=new KalaGameState(key);
}
catch(IOException e)
{
System.out.println(e);
}
}
Run Code Online (Sandbox Code Playgroud)
当我输入无效数量的宝石时,我收到此错误
线程"main"中的异常InvalidStartingStonesException:起始宝石的数量必须大于0且小于或等于10(尝试22)
为什么不是由我定义的throw处理的异常
KalaGame.<init>(KalaGame.java:27) at PlayKala.main(PlayKala.java:10)
| 归档时间: |
|
| 查看次数: |
266 次 |
| 最近记录: |