@justsml/

throwing-errors-in-javascript

Nodejs

using error constructor(s) correctly

fork
loading
Files
  • index.js

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.1837098994049382","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"CmNvbnN0IHRocm93VHlwZUVycm9yID0gKCkgPT4ge3Rocm93IFR5cGVFcnJvcignZXJyb3IhJyl9CmNvbnN0IHRocm93U3R1ZmYgPSAoKSA9PiB7dGhyb3cgJ25vdCByZWFsIGVycm9yLCBtYXRlISd9Cgp0cnkgeyB0aHJvd1N0dWZmKCkgfSBjYXRjaCAoZXJyb3IpIHsgY29uc29sZS5sb2coJ05vIFN0YWNrOiDinYwnLCBlcnJvcikgfQpjb25zb2xlLmxvZygnXG5cblxuJykKdHJ5IHsgdGhyb3dUeXBlRXJyb3IoKSAgfSBjYXRjaCAoZXJyb3IpIHsgY29uc29sZS5sb2coJ1N0YWNrZWQ6IOKchScsIGVycm9yKSB9Cgo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
const throwTypeError = () => {throw TypeError('error!')}
const throwStuff = () => {throw 'not real error, mate!'}

try { throwStuff() } catch (error) { console.log('No Stack: ❌', error) }
console.log('\n\n\n')
try { throwTypeError()  } catch (error) { console.log('Stacked: ✅', error) }

node v10.16.0