Separate the error handling into a different function.