Throw exception for invalid code