fix loop with exception error