error handling for while loops