Update the program to include error handling