Exception handling in jQuery plugins -


what considered best way handle misuse in jquery plugin -- ignore, or throw error? in situation i'm working with, have plugin binds functionality image. once bound, can other things through methods, e.g. set or state information can changed client interaction, e.g.:

$('selector').myplugin(); $('selector').myplugin('some-method',data); 

what should 1 when:

  • a selector contains no relevant elements (suspect answer is, nothing, no error)
  • a method, relevant bound element, applied selector no relevant elements
  • a method contains parameter data invalid

i feel right thing in cases ignore that's invalid or doesn't apply , proceed without errors. big part of "jquery way" act in predictable fashion as possible, me means, don't break unless have to.

on other hand, makes debugging more difficult, since won't ever errors when doing things aren't supposed to. reasonable (e.g., applying plugin set of elements subset relevant). on other hand, doing things trying apply specific method irrelevant element, or passing bad parameter data, cause more trouble in long run ignore errors.

is there conventional wisdom on this? add "ignore-errors" option?

on bullet 1 if following patterns on page http://docs.jquery.com/plugins/authoring, doing right thing. namely this:

var methods = { init : function( options ) {

   return this.each(function(){ 

on bullet 3 ignore parameter names don't use. throw exception when use bad data in 1 of parameters. believe stop processing of matched items in selector. provide debug mode throw exception. way can turn on during testing , leave off when go production.

on bullet 2 i'm tempted go picked out of said bullet 3. if getting data associated element hasn't had setxxxx called, return empty set of data.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -