【发布时间】:2020-08-31 19:20:48
【问题描述】:
这是可读流原生定义
// This is the part where you do stuff!
// override this function in implementation classes.
// 'chunk' is an input chunk.
//
// Call `push(newChunk)` to pass along transformed output
// to the readable side. You may call 'push' zero or more times.
//
// Call `cb(err)` when you are done with this chunk. If you pass
// an error, then that'll put the hurt on the whole operation. If you
// never call cb(), then you'll never get another chunk.
Transform.prototype._transform = function (chunk, encoding, cb) {
throw new Error('_transform() is not implemented');
};
所以在你自己的定义中,当你想传递一个错误时,你调用cb(new Error('...'))
但是当我这样做时,如果流是管道的,我怎么能捕捉到这些?
我的意思是不使用process.on('uncaughtException') 事件以正常方式捕获它们
【问题讨论】:
-
你的意思是 try...catch ?
-
无法尝试捕获,因为流异步
标签: javascript node.js error-handling node-streams nodejs-stream