throwif operator

Нурбек nurbek.ab at gmail.com
Tue Apr 11 12:06:38 UTC 2017


An example from node.js documentation:

fs.writeFile('message.txt', 'Hello Node.js', (err) => {
  if (err) throw err;
  console.log('The file has been saved!');
});

This looks like a common way to handle errors when the first parameter is
an instance of Error.

Yes, this line of code is short and easy to copy-paste.
But introducing something like this:

fs.writeFile('message.txt', 'Hello Node.js', (err) => {
  throwif err;
  console.log('The file has been saved!');
});

would make the code much cleaner and bring some sort of standart way to
handle such errors.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170411/02df95a6/attachment.html>


More information about the es-discuss mailing list