0

I'm a little curious to this exception when being thrown.

  public void addDailyUVReport(DailyUVReport report)
{
        counter++;
        if (counter > CAPACITY)
          throw new BackingStoreException("Called too many times");
}

How come that doesn't work? But... this does.

 public void addDailyUVReport(DailyUVReport report) throws BackingStoreException
  {
    counter++;
    if (counter > CAPACITY)
      throw new BackingStoreException("Called too many times");
  }

I know when you throw an IndexOutOfBoundsException() you do not need the throw clause? and can just create a new one without having the clause with the method. Would it have to do with it being void?

CabDude
  • 132
  • 2
  • 11

1 Answers1

1

Exceptions which extend RuntimeException are called unchecked and do not need to be declared in the method signature.

See here for more: Difference between Unchecked exception or runtime exception

Community
  • 1
  • 1
Kon
  • 10,702
  • 6
  • 41
  • 58
  • 1
    Oh okay, thanks. Actually just learned this in class today but he didn't really go over it. Just briefly explained it to us to get more familiar for later. Beginner programmer here o.o – CabDude Jan 30 '16 at 03:05