try-catch Block wrapped around the while-loop