I am getting exception in main thread...even when i am handling the exception
- by fari
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);
}
}
when i enter an invalid number of stones i get this error
Exception in thread "main" InvalidStartingStonesException: The number of starting stones must be greater than 0 and less than or equal to 10 (attempted 22)
why isn't the exception handled by the throw i defined at
KalaGame.<init>(KalaGame.java:27) at PlayKala.main(PlayKala.java:10)