开发者

Best practices for error handling in jQuery plugin

What are 开发者_如何学运维some of the best practices for handling errors from within a custom jQuery plugin?

So far I am checking for the error conditions, using console.log and returning from my plugin. The idea is that I dont want to stop any other js on the page from working but still provide an error message to the user.

The type of error conditions in particular I am thinking of are required parameters being passed in to te plugin etc.

I am new to writing jquery plugins so please excuse this if it is a stupid question.

I just really want to know from experienced developers what they do with regards to this.


The best practice would be to have default values set for all your required options. If options are implemented correctly allow the user to over ride them should not be an issue.Setting options to have default values Handling the user changing options


I tried to create a plugin which can handle error in JavaScript. At the time of error, you have to call this plugin to log/notify and handle your code.

something like below
try{
alert (undeclaredVariable);
}catch (e)
{
//call mentioned plugin
}

http://prcoldfusion.blogspot.com/2012/03/error-handling-in-javascriptjquery.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜