Modified code to use exceptions.