Java: Code not running after for loop?
public static String getElementXpath(DOMElement elt){
String path = "";
for (; elt != null; elt = (DOMElement) elt.getParentNode()){
System.out.println("THIS ONE " + path);
}
System.out.println("NEXT ONE " + path);
return p开发者_如何学编程ath;
}
NEXT ONE doesn't even print. I've tried adding anything after the for loop but they don't seem to be running. Shouldn't there be exception that is raised that I can catch? My main method which executes the function getElementXpath throws Exception. I tried removing the throw Exception and same result.
Swallowing an exception somewhere else seems to be the only explanations possible. Encapsulate the loop in a try-catch block, print the exception and rethrow. For testing, catch Throwable. Maybe add a finally block, too.
My main method which executes the function getElementXpath throws Exception.
This doesn't matter, there may be a RuntimeException or even an Error. You shouldn't declare throws Exception
without a reason, but it can't be the culprit here.
path
is initialized with "", but never assigned again.
精彩评论