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.

Related concepts

How to Throw Exceptions

Exceptions: How to Throw Exceptions — Structure map

Clickable & Draggable!

Exceptions: How to Throw Exceptions — Related pages: