Tag: exception处理

“在Foreach node.js中,迭代器不提供'throw'方法

我遇到了nodejs生成器的麻烦,当我启动我的代码时,我得到了以下错误: node:3632) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: The iterator does not provide a 'throw' method. (node:3632) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 代码如下,我使用AdoniJs。 User.all和user.typeModule都是数据库关系。 // This is the function that is called […]

如何find哪些promise在nodejs中未处理UnhandledPromiseRejectionWarning?

从版本7的nodejs有asynchronous等待处理承诺的sintactic糖,在我的apis下面的警告经常出现: (node:11057) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: Error: Can't set headers after they are sent. (node:11057) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 不幸的是,没有提到渔获缺失的地方。 有没有办法find它没有检查每个try catch块?

UnhandledPromiseRejectionWarning:不清楚警告的文件或行

我得到了几个类似于这个错误的错误: (node:30892) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): SyntaxError 从这些问题( 什么是未处理的诺言拒绝和NodeJS未处理的 拒绝警告)看来,这些警告是由于没有一个承诺。 但是,这些警告没有问题所在的文件或行号。 有什么方法可以find/缩小它?

如何打印JavaScript的exception完整回溯?

当我的Node.js应用程序抛出一个exception时,打印的堆栈跟踪被限制在10的深度。不幸的是,有时候这还不够深,无法findexception的来源。 有没有办法configuration节点打印一个更深的回溯exception?

Express 4 / Node JS – 非常好地pipe理uncaughtException

我尽我所能确保我的代码中没有错误,但是偶尔会有一个未捕获的exception来杀死我的应用程序。 我可以用它做,而不是杀死应用程序,而是将其输出到某个文件,然后尝试从应用程序停止的位置恢复 – 或者静静地重新启动,并向应用程序中的所有用户显示出错信息,给它一秒钟,而它自行sorting。 如果应用程序没有运行,它会很好,如果它可以redirect到某个地方,说“该应用程序没有运行,取得联系,让我知道”或类似的东西。 我可以使用process.on('uncaughtException')… – 但这是正确的事情吗? 非常感谢您花时间阅读本文,感谢您对此事的帮助和想法。

允许chai / mochatesting将错误冒泡到process.on

我正在编写一个捕获顶级未捕获错误的节点模块,并希望为其编写一些testing。 不幸的是,我最喜欢的框架似乎有意识地抛出和捕获未捕获的exception的问题。 如果我抛出exception,那么错误,然后testing失败。 如果我抛出并捕获错误,它不会冒泡process.on('uncaughtException') 代码atm不起作用 it('Catches errors and return the user and line number', function(done) { blame.init(function (res) { console.log('\n\n', res, '\n\n'); expect(true).should.equal(true); done(); }); expect(function () { undefinedFunction(); }).to.throw('undefinedFunction is not defined'); });

node.js承诺:如何找出哪个迭代抛出.catch语句中的exception?

(这不是JavaScript内部循环的重复- 简单实用的例子,因为你不能selectcatch函数采用哪些参数) 我不熟悉Node.js的asynchronouscallback性质 我试图找出for循环中的哪个元素抛出exception。 当前的代码总是返回数组中的最后一个元素,而不pipe哪个元素抛出exception。 for (i = 0; i < output.length; i++) { var entity = Structure.model(entity_type)[1].forge(); /* do some stuff here which I've taken out to simplify */ entity.save() .then(function(entity) { console.log('We have saved the entity'); console.log(entity); returnObj.import_count++; }) .catch(function(error) { console.log('There was an error: ' + error); console.log('value of entity: ', entity); […]

捕获node.js中的未捕获exception的源或行号

我有一个运行在IIS中的node.js express应用程序。 我发现应用程序经常因为一些未捕获的exception而崩溃。 因此,我用process.on('uncaughtException')来重新启动服务,以防未捕获的exception。 我可以把错误当作“ECONNRESET”,但我无法得到这个实际发生的地方。 有什么办法来捕获导致exception的错误源或行号?

节点不抛出堆栈溢出exception

我试图用这个代码强制堆栈溢出: // Throws stack overflow exception var count = 0; try { (function curse() { console.log(count++); curse(); })(); } catch (e) { console.log('ERROR'); console.log(e.message); } 但是,当我运行它时,它将数字打印到屏幕上,然后优雅地退出。 没有exception抛出,我可以删除try-catch ,仍然没有任何exception输出到控制台。 为什么我不能获得转储到控制台的exception消息? 节点版本是v0.12.2 ,V8是3.28.73 。

错误事件不处理ECONNREFUSED错误,尝试捕获

我正在使用npm请求模块将传入请求转发到另一台服务器,如下所示: app.get("/somepath", function(req, res) { var url = proxySetting.global.url + req.url; req.pipe(request(url)).pipe(res); }); 这里:proxySetting.global.url == http:// localhost:4000 现在,当我将这样的传入请求转发到目标服务器时,如果目标服务器(localhost:4000)closures或请求在目标服务器上被挂起。 会出现ECONNREFUSED或挂断错误等错误。 尝试使用下面的域模块捕获这些错误 var d = domain.create(); d.on("error", function(err) { console.log("Error occoured while forwarding request"); console.log(err); res.status(500).send("Error occoured while forwarding request"); }); d.run(function() { req.pipe(request(url)).pipe(res); }); 试图在几个组合中发现错误事件 var request = require("request"); module.exports = function(proxySetting) { return function(req, res, […]