jQuery API

jQuery.error

jQuery.error( message )

Description: Takes a string and throws an exception containing it.

  • version added: 1.4.1jQuery.error( message )

    messageThe message to send out.

This method exists primarily for plugin developers who wish to override it and provide a better display (or more information) for the error messages.

Example:

Override jQuery.error for display in Firebug.

jQuery.error = console.error;

Comments

  • Support requests, bug reports, and off-topic comments will be deleted without warning.

  • Please do post corrections or additional examples for jQuery.error below. We aim to quickly move corrections into the documentation.
  • If you need help, post at the forums or in the #jquery IRC channel.
  • Report bugs on the bug tracker or the jQuery Forum.
  • Discussions about the API specifically should be addressed in the Developing jQuery Core forum.
  • I generally stub out the console (based on firebug) for browsers without one. I also tend to throw an error within try/catch blocks. I really don't see an inherit advantage here.

    try {
    var tmp = doSomething();
    if (tmp == something.errorCondition)
    throw new Error("Error condition in X");
    } catch(err) {
    //handle ((err && err.message) || err.toString())
    }
  • Throwing an exception within a try block will just catch the exception in the catch-block - whats the point?
  • Suresh
    I can use jquery.error like this
    <script type="text/javascript">
    jQuery(function(){jQuery.error = console.error;
    console.log("My test message");
    jQuery.error("mytest error message");

    });
    </script>

    Is there any other ways or advantages of this jQuery.error usage?