Fix crash if underlyingError parameter is nil.

Fixes #348.