Corrected program termination when input is invalid

Nested the program under a do-try-catch-while.