I am getting exception in main thread...even when i am handling the exception
Posted
by fari
on Stack Overflow
See other posts from Stack Overflow
or by fari
Published on 2010-04-10T20:52:34Z
Indexed on
2010/04/10
21:03 UTC
Read the original article
Hit count: 425
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)
© Stack Overflow or respective owner