Node.js
的错误有以下几种:
eval error
、syntax error
、range error
、reference error
、type error
、uri error
try {
const a = 1
const c = a + b
} catch (err) {
console.log(err)
}
以上代码输出ReferenceError:b is not defined
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)