src: only access stack of defined errors

Avoid segmentation fault when `undefined` is thrown