Fix exception handling so invalid value length throws expected exception