admin管理员组文章数量:1389749
I have a page on which mysterious JavaScript errors keep popping up. They appear to be ing from the application we use and do not own the source for. I'm working on a real solution to this issue, but we have a demo tomorrow and I was wondering if there is a way to just suppress JS errors page wide (like wrapping ALL the javascript ponents in a giant try catch).
I have a page on which mysterious JavaScript errors keep popping up. They appear to be ing from the application we use and do not own the source for. I'm working on a real solution to this issue, but we have a demo tomorrow and I was wondering if there is a way to just suppress JS errors page wide (like wrapping ALL the javascript ponents in a giant try catch).
Share Improve this question asked Jan 31, 2011 at 2:49 MaxxMaxx 4,0828 gold badges34 silver badges38 bronze badges 5- 1 What's a giant try catch going to do? It'll make your code fail silently, not work correctly. – Matt Ball Commented Jan 31, 2011 at 2:50
- @Matt well, if it works for the demo... See more info here. A giant try/catch seems to be the tool of choice – Pekka Commented Jan 31, 2011 at 2:52
- 1 @Pekka: eh, I guess... seems rather weak. – Matt Ball Commented Jan 31, 2011 at 2:53
-
2
@Matt,
sed 's/seems rather/is totally/'
– ocodo Commented Jan 31, 2011 at 3:24 - 2 I would not use one giant try-catch. It will make identifying and fixing your bugs (or even their bugs) so much harder. Consider using a wrapper around said API that you can control and wrap the individual actions (may be object-based or operation-based). – user166390 Commented Jan 31, 2011 at 3:27
1 Answer
Reset to default 10You could add a handler to the window.onerror event. In this case, all the errors that occur inside the window will be redirected to the handler of this event. (I did test this in Firefox and it worked, but I was having trouble with it in Chrome - my Chrome installation is pretty messed up, so that could be the problem, but there are Chromium bugs filed that relate to this issue: bug #7771 and bug #8939)
window.onerror = function (msg, url, line) {
alert("Error on line " + line + " in " + url + ":\n" + msg);
// return true to prevent browser from displaying error
return true;
}
本文标签: javascriptIs there a way to trycatch an entire page dynamicallyStack Overflow
版权声明:本文标题:javascript - Is there a way to trycatch an entire page dynamically? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744722160a2621758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论