Exceptions: How to Throw Exceptions
How to Throw Exceptions
public Object pop() {
Object obj;
if (size == 0) {
throw new EmptyStackException();
}
obj = objectAt(size - 1);
setObjectAt(size - 1, null);
size--;
return obj;
}
Exception is always thrown with the throw statement.
The throw statement requires a single argument: a throwable object. Throwable objects are instances of any subclass of the Throwable class.