title: When developing a library, should we throw errors/exceptions?
body: <p>I'm developing a pub/sub Mediator library to be used by others and I don't know how to handle errors.</p>
  
  <p>Here's an example piece of code:</p>
  
  <pre><code>/**
   *
   * @param String channel Channel to subscribe
   * @param String|function callback Function name or callback
   * @param String context Context to bind function to
   * @param Boolean once True to subscribe once
   **/
  this.subscribe = function (channel, callback, context, once) {
  
      if (!_.isObject(context)) {
           context = window;
      }
  
      if (!_.isFunction(subscription) &amp;&amp; !_.isFunction(context[subscription])) {
          throw new Error('Function passed as callback to channel subscription named  ' + channel + ' seems invalid!');
      }
  
      // Everything ok, add to channels object
      channels[channel].push({fn: subscription, context: context || this, once: once});
  }
  </code></pre>
  
  <p>This method is part of the library. It's API expects a channel name and a valid callback (either the function name, a lambda or a callback).</p>
  
  <p>If the channel argument is not a string, the library readily stop. If an invalid context is passed, window is assumed. Mistakes in both these parameters are easily debugaable. </p>
  
  <p>However, if an invalid callback is passed, it propagates the error until an event is fired (a channel publishing is made). In a pub/sub system this might become a nightmare to debug if, for instance, the event is rarely fired.</p>
  
  <hr>
  
  <p><strong>So my question is...</strong> </p>
  
  <p>In this specific scenario, taking in account that I'm developing a javascript library to others, should I:</p>
  
  <ul>
  <li>throw Errors to prevent further error propagation?</li>
  <li>return false/undefined/-1 and not register the subscription?</li>
  <li>proceed as normal at let it die somewhere, leaving the debugging to the third party developer</li>
  </ul>
  
  <hr>
  
  <p>NOTE:
  There's <a href="https://stackoverflow.com/questions/8689516/js-library-best-practice-return-undefined-or-throw-error-on-bad-function-input">a similar question</a> but my situation is a bit different and the answers provided didn't put my spirit at ease.</p>