Raise ValueError if program is invalid