if (win.NS && win.NS.molist && win.NS.molist.utility) {
NS = win.NS;
NS.molist.dom = true;
} else {
throw "dom requires utility module";
}
对于上面的代码段,如果win.NS.molist.utility
不存在,那么抛出错误的正确方法是什么?
我可以直接抛出我想要显示的文本以显示在调试器中吗?
也许,我应该使用其中一种内置错误类型?
也许是new TypeError
,我不确定是否有很多全局错误对象。
答案 0 :(得分:3)
您可以throw
完全自定义错误。
function ModuleNotFoundError(message) {
this.name = "ModuleNotFound";
this.message = message || "dom does not have this module";
}
ModuleNotFoundError.prototype = new Error();
ModuleNotFoundError.prototype.constructor = ModuleNotFoundError;
throw new ModuleNotFoundError('win.NS.molist.utility');