如果findByElem抛出异常,是否可以在另一个函数中测试? 例如主调用findByElem,如何测试是否抛出异常(没有findByElem重新抛出异常)?
public TNode findByElem(T _elem) {
LLNode<T> node = root;
while (node != null && node.elem.compareTo(_elem) < 0) {
node = node.next;
}
if (node == null || node.elem.compareTo(_elem) != 0) {
throw new RuntimeException("Node "+_elem.toString() + " could not be found in linked list");
}
return node.ptr;
}