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.
 if (!  (fs.existsSync('program')))
 console.log('Compile Fail');
 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 {
 } catch (ex) {