开发者

Is it possible to surround all my javascript file with one try catch?

I wrote a bookmarklet, when the user will click on it in his browse开发者_Go百科r it will do some actions on the current website and show some results in a popup.

In some websites my bookmarklet fails to load because problems may exist in the current website.

My bookmarklet code is using the jquery library.

In some cases the errors happens in the jquery library because some conflicts or something i don't know.

My Question is:

Can i surround all my bookmarklet code with one try catch which will catch any error happen in all my code and redirect the user to another page 'error page'?


Errors will bubble down the stack towards the original calling function, so if you wrap your entire top-level code with a try...catch then jQuery errors will be caught.

http://jsfiddle.net/NcEpe/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜