jQuery.error()
JQ Home <<
Core & Internals <<
jQuery.error()
Throw an exception.
Shorthand version $.error()
Description
The jQuery.error()
method allows throwing of an exception from a passed string.
Syntax
Signature | Description |
---|---|
jQuery.error( errorMessage ) | Throw an exception from a passed string. |
Parameters
Parameter | Description | Type |
---|---|---|
errorMessage | The error message string to send. | String |
Return
None.
jQuery.error( errorMessage )
Example
Core << Top
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.
$(function(){
$('#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);
}
});
});
Related Tutorials
jQuery Basic Tutorials - Lesson 2 - jQuery Core & Internals