Add an option to capture error messages in a variable instead of terminating with a fatal error. Fixes: #25778