3
我的应用程序正在使用其他一些指令,我无法控制其他指令,我想用一些信息来增加这些指令中出现的任何错误,以便我知道哪些错误来自我自己,以及哪些不是。所以我试图写我自己的指令,它编译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>
如若这项工作?