throw an exception on a method call
error-handling, exception, java, throws
Solution
Try this.
@Override
public void remove() {
throw new UnsupportedOperationException();
}
Problem
How do I throw and UnsupportedOperationException on a method? So if I have an Iterable object and I'm trying to disallow the remove method for that object. In the method below I'm returning an iterable object whose iterator's remove I need to disable by throwing an UnsupportedErrorException. Can I do this within the body of the method or how so? ``` public Iterable<String> getInNodes (String destinationNodeName) { if (!hasNode(destinationNodeName)) return emptySetOfString; else { for(String e : nodeMap.get(destinationNodeName).inNodes) { emptySetOfString.add(e); } return emptySetOfString; } } ```