如何在启动成功后输出到控制台"SUCCESS",而在启动失败后输出"ERROR"?

How to output to the console "SUCCESS" after a successful launch, and "ERROR" after an unsuccessful one?

问题是:

我目前正在使用 Puppeteer 库 Node.js,我需要打印 "SUCCESS" 成功后 运行 和 "ERROR" 失败后 运行。但是我不太明白怎么做。

感谢大家的帮助。

console.log('Success'); console.log('error'); https://nodejs.dev/learn/output-to-the-command-line-using-nodejs

你可以把整个事情包装在一个 try...catch

try {
  // Your Code Here
  console.log('Success')
} catch (e) {
  console.log('Error')
}