give exception a nice message (closes #22379)

Patch by Yongzhi Pan.