Add exception handling for errors

The user input parsing used to have no error handling code, now try and
except are added to terminate the program gracefully.