I am playing around with a card game in Java using NetBeans. I found a IndexOutOfBounds error, which I fixed, but then I thought about trying some error handling. SO I played with try and catch, and throw new... and then I looked at throwing the exception up to the calling method. So I added throw Exception:
public Card getCard(int position) throw Exception
{
return hand.get(position);
}
This required me to handle the exception in all the methods that called getCard() which is not what I wanted. So I removed it. But now I can't run the program, I get:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source
code - unreported exception java.lang.Exception; must be caught or declared
to be thrown
at Games.Cards.Cribbage.CompHandPicker.pickHand(CompHandPicker.java:32)
at Games.Cards.Cribbage.Main_Game.main(Main_Game.java:44)
C:\Users\hugh_\AppData\Local\NetBeans\Cache\8.2\executor-
snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
I assume it is looking for that thrown Exception. What do I do?
EDIT: After messing around, my code is back to the way it was at the beginning (but with the a -1 to avoid IndexOutOfBoundsException) and all of a sudden it works. I really don't know what changed or why.