adding an exception

I'm trying to make my own exception to a program.

I'm getting an error here
-  public boolean addBox(Box b) throws InsufficientSpaceException
Error: incompatible types
found   : InsufficientSpaceException
required: java.lang.Throwable

Here are my files:
---------------------------------------------------
import java.lang.Throwable;

public interface BinCollection {
 
 
public boolean addBox(Box b) throws InsufficientSpaceException;
 
public int size();
}

--------------------------------------------------
public interface InsufficientSpaceException {
 
  /**
   * Constructs a InsufficientSpaceException with no detail message.
   */
  public void InsufficientSpaceException();
 
}

----------------------------------------------------------
import java.util.ArrayList;
import java.awt.*;
import java.lang.Throwable;

public class SimpleBinCollection
  implements InsufficientSpaceException, BinCollection {
 
  private ArrayList<Bin> bins = new ArrayList<Bin>();
 
  /**
   * Default constructor. We could leave this out, and it would be
   * created for us just like this.
   */
  public SimpleBinCollection() {
  }
 
  /**
   * Adds a box to the BinCollection.  The method uses the following algorithm:
   * If the box is bigger than the capacity of a bin, throw an exception.
   * Otherwise, scan through the bins to find a bin with enough available space.
   * If such a bin exists, add the box to the bin.
   * Otherwise, create a new bin and add the box to the new bin.
   * @param b The Box
   * @return status: 0 = OK, -1 = too-big
   */
  public boolean addBox(Box b) throws InsufficientSpaceException{
    if (b.height() > Bin.CAPACITY)
    return false;
    for (Bin bin: bins) {
      if (b.height() <= bin.availableSpace()) {
        bin.addBox(b);
        return true;
      }
    }
    Bin bin = new Bin(bins.size());
    bin.addBox(b);
    bins.add(bin);
    return true;
  }
 
  /**
   * Returns the number of bins in the BinCollection
   *
   * @return The number of bins
   */
  public int size() {
    return bins.size();
  }
 
  /**
   * Overrides the default method.
   * @return A string representation of the BinCollection
   * with one line for each Bin
   */
  public String toString() {
    StringBuffer s = new StringBuffer();
    for (Bin bin: bins)
      s.append("" + bin + "\n");
    return s.toString();
  }

  /**
   * Constructs a InsufficientSpaceException with no detail message.
   */
  public void InsufficientSpaceException() {
  }
}
no158Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kannan EkanathCommented:
java.lang.Throwable or java.lang.Exception must be a part of your class hierarchy.
Kannan EkanathCommented:
public class SimpleBinCollection extends Throwable
  implements InsufficientSpaceException, BinCollection

is one option. However i would advice you to rethink your strategy.

Make InsufficientSpaceException a class(not an interface and extend java.lang.Exception)

then your,
public class SimpleBinCollection extends  InsufficientSpaceException implements  BinCollection

This would be the ideal way

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mick BarryJava DeveloperCommented:
probably should be:

public class InsufficientSpaceException extends Exception {
 
  /**
   * Constructs a InsufficientSpaceException with no detail message.
   */
  public void InsufficientSpaceException()
  {
      super("Insufficient space");
   }
}
Kannan EkanathCommented:
>> Make InsufficientSpaceException a class(not an interface and extend java.lang.Exception)

Arent both same?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.