jQuery.error()S2C Home « Core & Internals « jQuery.error()

Throw an exception.

Shorthand version  $.error()


The jQuery.error() method allows throwing of an exception from a passed string.


Signature Description
jQuery.error( errorMessage )Throw an exception from a passed string.


Parameter Description Type
errorMessageThe error message string to send.String



jQuery.error( errorMessage ) ExampleTop

Throw an exception from a passed string.

This method isn't much use outside of plugins as we can use the try....catch....finally construct for much better error handling. It does however give plugin developers the opportunity to override it with more meaningful error messages.

  $('#btn3').on('click', function() { 
    try {
      var anError = 3;
      if (anError < 5) {
        jQuery.error('ERROR: Value less than 5');
    } catch(e) {
      alert(' Our Message: ' + e.message);

Press the button below to action the above code: