exit with the correct error code