Move try catch in for loops