For the below code:
const testStringify = () => {
try{
console.log('Inside testStringify');
const a = "";
a.b.c;
} catch(err) {
console.log('Inside catch of testStringify');
console.log(`Error: ${JSON.stringify(err)}`);
console.log(err);
}
}
testStringify();
The output is:
Inside testStringify
Inside catch of testStringify
Error: {}
TypeError: Cannot read property 'c' of undefined
at testStringify
at Object.<anonymous>
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Why does Json.stringify(err) (Error: {}) not print output in the same way or in some meaningful way as console.log(err)?