src: only access stack of non-null errors

Avoid segmentation fault when `null` is thrown

The same as #6649, but for `null`.

/cc @tjfontaine @rlidwka