check that exception messages are not empty (#22379)

Patch by Yongzhi Pan.