Add exception handling in loops.