Nodejs教程
Nodejs Mysql
Nodejs MongoDB
Nodejs 对比

Node.js 错误

Node.js错误

Node.js应用程序通常会遇到四种类型的错误:
标准JavaScript错误,即<EvalError>,<SyntaxError>,<RangeError>,<ReferenceError>,<TypeError>,<URIError>等 系统错误 用户指定的错误 断言错误

Node.js错误示例1

让我们以部署标准JavaScript错误为例-ReferenceError。
文件: error_example1.js
// throws with a ReferenceError because b is undefined
try {
  const a = 1;
  const c = a + b;
} catch (err) {
  console.log(err);
}
打开Node.js命令提示符并运行以下代码:
node error_example1.js
Node.js错误示例1

Node.js错误示例2

文件: timer2.js
const fs = require('fs');
function nodeStyleCallback(err, data) {
 if (err) {
   console.error('There was an error', err);
   return;
 }
 console.log(data);
}
fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback);
fs.readFile('/some/file/that/does-exist', nodeStyleCallback);
打开Node.js命令提示符并运行以下代码:
node error_example2.js
Node.js错误示例2
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4