Throwing Exceptions in Java Programming
Previous | Home | Next |
Throw statement is used to throw an exception or simply use the throw keyword with an object reference to throw an exception.
To throw an exception a single argument is required by the throw statement i.e. a throwable object. As mentioned earlier Throwable objects are instances of any subclass of the Throwable class.
public Object pop()
{
Object obj;
if (size == 0) {
throw new EmptyStackException();
}
obj = objectAt(size - 1);
setObjectAt(size - 1, null);
size--;
return obj;
Previous | Home | Next |