[#1388] Correctly break the loop on exceptions