I wanted to get the boolean status from a function. Here is my sample code, wherein I used return in try and catch, to get the status of function.
public static void main(String[] args) {
System.out.println(getState() ? "successful" : "failed");
}
public static boolean getState() {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("tile.xml");
Set<String> set = new TreeSet<String>();
try {
Document document = (Document) builder.build(xmlFile);
Element rootNode = document.getRootElement();
System.out.println(rootNode);
return true;
} catch (IOException io) {
System.out.println(io.getMessage());
return false;
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
return false;
}
}
Does it makes sense ? Can I improve it ? Assuming, that there might be more than 10 catch blocks, then should I use 10 return statements, in each catch block.