Catch exception when program check has non-zero return code

See #1175.