Handle errors with a switch statement