E
exquisitus
I've just been browsing through the Java tutorial which describes a
Nonruntime excption as:
"Nonruntime exceptions are exceptions that occur in code outside of the
Java runtime system. For example, exceptions that occur during I/O are
nonruntime exceptions. The compiler ensures that nonruntime exceptions
are caught or specified; thus, they are also called checked exceptions."
Later
(http://java.sun.com/docs/books/tutorial/essential/exceptions/throwing.html)
the tutorial then lists the ff code:
public Object pop() throws EmptyStackException {
Object obj;
if (size == 0) {
throw new EmptyStackException();
}
obj = objectAt(SIZE - 1);
setObjectAt(SIZE - 1, null);
size--;
return obj;
}
And states: "Note that the declaration of the pop method contains a
throws clause. EmptyStackException is a checked exception"
My question is that why is EmptyStackException a checked exception (when
NullPointerException for example - is unchecked?). Surely, the
designation annot be arbitary?
Could someone please provide a simpler/less ambiguous explanation of the
logic behind Checked and Unchecked exceptions?
Many Thanks
Nonruntime excption as:
"Nonruntime exceptions are exceptions that occur in code outside of the
Java runtime system. For example, exceptions that occur during I/O are
nonruntime exceptions. The compiler ensures that nonruntime exceptions
are caught or specified; thus, they are also called checked exceptions."
Later
(http://java.sun.com/docs/books/tutorial/essential/exceptions/throwing.html)
the tutorial then lists the ff code:
public Object pop() throws EmptyStackException {
Object obj;
if (size == 0) {
throw new EmptyStackException();
}
obj = objectAt(SIZE - 1);
setObjectAt(SIZE - 1, null);
size--;
return obj;
}
And states: "Note that the declaration of the pop method contains a
throws clause. EmptyStackException is a checked exception"
My question is that why is EmptyStackException a checked exception (when
NullPointerException for example - is unchecked?). Surely, the
designation annot be arbitary?
Could someone please provide a simpler/less ambiguous explanation of the
logic behind Checked and Unchecked exceptions?
Many Thanks