refactor exception block with retry