Thread: JAVA Exception
View Single Post
  #2 (permalink)  
Old Aug 30th, 2007, 20:37
hschmitz hschmitz is offline
Up'n'Coming Member
Join Date: Jun 2007
Location: Birmingham, UK
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: JAVA Exception

The throw keyword is used to actually throw an exception while the throws keyword just tells the compiler which exceptions may be thrown by a method.

Code: Select all
public Object pop() throws EmptyStackException
{
    Object obj;

    if (size == 0) {
        throw new EmptyStackException();
    }

    obj = objectAt(size - 1);
    setObjectAt(size - 1, null);
    size--;
    return obj;
}
See haw throws appears in the declaration of the method and throw appears in its body.
Reply With Quote