check that exception messages are not empty (#22379)

Patch by Yongzhi Pan.
merge 3.4 (#22379)