BUG: variable not defined in exception