Execsync does not throw an error when the return value is not zero.

  node.js, question

I need to implement a program to judge whether the compilation passes. Then I wrote the following code.

var execSync = require('child_process').execSync;
 var fs = require('fs');
 
 Var cmd = 'g plus program.
 console.log(cmd);
 execSync(cmd);
 if (!  (fs.existsSync('program')))
 console.log('Compile Fail');
 else
 console.log('Compile Success');

If the compilation is successful, there is no problem, but if the compilation fails, execSync will throw an error, and the official website also has the following instructions:

If the process times out, or has a non-zero exit code, this method will throw. The Error object will contain the entire result from child_process.spawnSync

But I don’t want it to throw errors, but continue to executeconsole.log('Compile Fail');What should I do with this statement? ?

try {
 execSync(cmd);
 } catch (ex) {
 
 bracket