pakut2
pakut2

Reputation: 672

Is it necessary to explicitly handle Node.js stream errors?

I'm using the archiver package in order to compress files and upload them via a stream.

It's my first time using streams in Node.js, and in the documentation of archiver I have stumbled upon the following case:

// good practice to catch this error explicitly
archive.on('error', function(err) {
  throw err;
});

In this scenario, is it necessary to listen on error just to throw it? Does it make any difference if I simply omit this step?

If not, why is it considered a good practice by the docs?

Upvotes: 1

Views: 47

Answers (0)

Related Questions