Originally posted by Vlada Den:
Thank you for reply, George. But where can I declare, that the method throws an exception?
public Object remove() {
Object firstOne = head.obj;
head = head.next;
if (head == null)
tail = null;
size--;
return firstOne;
}
throws java.util.NoSuchElementException {
throw new java.util.NoSuchElementException("exception");
void mindException() {
try {
remove();
} catch (java.util.NoSuchElementException e) {
}
}
}
}
Vlada
I think he already answered your question. The "throws" clause goes immediately at the end of the method header and right before the opening { for the method body. The "throw new java.util.NoSuchElementException()" call can go anywhere you like to have it in the method body. When I can, I check for error conditions at the beginning so I can throw exceptions as soon as possible.
Also please use
UBB CODE tags to preserve your code formatting. As Nick says, people are more likely to help if they can easily read your code.
Layne