gpt4 book ai didi

java - 我在主线程中遇到异常......即使我正在处理异常

转载 作者:行者123 更新时间:2023-11-29 07:22:12 25 4
gpt4 key购买 nike

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);
}
}

当我输入无效数量的石头时,出现此错误

线程“main”中的异常InvalidStartingStonesException:起始石子的数量必须大于0且小于或等于10(尝试22)

为什么我定义的throw没有处理异常

KalaGame.<init>(KalaGame.java:27) at PlayKala.main(PlayKala.java:10)

最佳答案

您只处理 IOException 而不是抛出的异常,即 InvalidStartingStonesException

关于java - 我在主线程中遇到异常......即使我正在处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2614930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com