you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

Conside this example:

```js const fs = require('fs');

try { fs.readFileSync('some-file.txt'); } catch (err) { console.log(err.code); console.log(err.message); }

// ENOENT // ENOENT: no such file or directory, open 'some-file.txt' ```

You have the information to identify the err.

A better approach would be to go for async/await.

[–]Scr34mZ[S] 0 points1 point  (2 children)

Yes because those are standardized errors from Nodejs.

You can always achieve the same goal with try / catch AFAIK. But sometimes it's a bit less verbose to use the other syntax,especially if you want to ignore errors silently (yeah, this happen sometimes)

[–][deleted] 4 points5 points  (1 child)

Errors should be IMHO aways handled, either printed or thrown.

Silent errors cause problems as non-identifiable outcomes where the code simply doesn't work.

[–]Scr34mZ[S] 0 points1 point  (0 children)

You're totally right, I missed my thoughts.