0

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.

  • Possible duplicate of [unreported exception java.io.IOException; must be caught or declared to be thrown](https://stackoverflow.com/questions/8707906/unreported-exception-java-io-ioexception-must-be-caught-or-declared-to-be-throw) – kryger Oct 13 '17 at 14:29
  • It worked fine before I added, then removed the throw Exception – Hugh Crawford Oct 13 '17 at 14:36
  • Your IDE may not have rebuilt the project after you saved the changes. It's definitely not a Java language or compiler issue. – kryger Oct 13 '17 at 18:07

0 Answers0