【发布时间】:2015-12-06 13:17:49
【问题描述】:
我需要一个模块并将其保存在一个变量中。但是当我用错误的名称调用模块函数时,它不会抛出任何错误或控制台任何错误。如何使这个抛出错误?
var module = require('../pre_process/' + preProcessFolder + '/' + preProcessModule);
// module -> { XYZ: [Function] }
//Following does not throw error and doesn't console anything.How to handle/debug this error
module['XY'](result, userId)
.then(function(recData) {
})
我正在使用 q 库来实现承诺。
【问题讨论】:
-
整个代码本身是否在 promise 的
.then()中?在这种情况下,它可能会抛出,但您可能没有.catch()外面。 Checkout Bluebird promise 库,它非常适合自动记录此类未捕获的错误 -
@jondoe:我问自己,你想做什么,为什么?完全动态地包含一个模块对我来说毫无意义。