Often I came across situations like this, how to write this code in a neat and clean way. One more issue I find here is performance as I am iteration a list and then it's properties.
Edit : - while the suggested How to tackle a 'branched' arrowhead anti-pattern? post address the nested if-elseif-if concern to a great extends. Still, I am looking for an answer for how to handle multiple try catch in (if any) in the code, and how to improve performance.
for (String item : someList) {
IResultOne resultOne = doSomething(item);
if (resultOne != null) {
for (SomeObject obj :resultOne.getSomeOtherList) {
IResultTwo resultTwo = doMegaProcessing(obj);
if(resultTwo != null) {
try {
doSomeMoreProcessing(resultTwo);
}
catch (CanNotProcessingException ex) {
errorObj.addError("can't process reason");
}
}
else {
errorObj.addError("item does not have {} error ");
}
}
}
else {
errorObj.addError("item is invalid "+item)
}
}