Throw better exceptions on invalid data