我的应用程序正在使用一些我无法控制的其他指令,我希望能够通过添加一些信息来增强来自这些指令的任何错误,以便我知道哪些错误来自我自己,哪些不是。因此,我尝试编写自己的指令,它会在try/catch块中编译任何内容,以便我可以捕获错误并适当处理它们。
结果发现以下代码将无法捕获任何错误,可能是因为编译是异步执行的?
// in compile fn:
foreignEl = element.contents().remove();
// in link fn:
element.append(foreignEl);
try{
$compile(foreignEl)(scope)
} catch(e){
console.error("NOT MY FAULT: " + e.message);
}
我考虑使用以下指令:
我在思考如何使用这个指令:
<my-error-catcher>
<the-foreign-directive>
</the-foreign-directive>
</my-error-catcher>
这个会起作用吗?