I don't think it's good practice to check the loop variable `i` after the loop has returned. Why not to just write it as:
`if (!ret_val) throw ....`.