jQuery.error(message) (alias $.error) takes a string and throws an exception containing it (added in jQuery 1.4.1). Plugin authors can override the function for logging or richer display.
Remember
jQuery.error(message) → throws (no normal return)
try {
$.error("Missing option");
} catch (err) {
console.log(err.message); // "Missing option"
}
// Official override pattern:
jQuery.error = function (message) {
sendErrorLog("jQuery error: " + message);
throw new Error(message); // still throw!
};
Pass a message string; catch it if the caller should recover.
Detect an invalid state in a plugin (missing option, bad type, etc.).
Call jQuery.error("clear message") — execution stops there unless caught.
Optionally override jQuery.error once for app-wide logging.
In the override, log first, then throw new Error(message).
Piece
Required?
Role
message
Yes
String included in the thrown error
Return
—
Does not return — throws
Override
Optional
Log / display, then throw again
Pseudocode
Pseudocode
function error(message):
throw exception with message
// Plugin check:
if options.color is missing:
jQuery.error("spotlight: options.color is required")
// Override (official idea):
jQuery.error = function (message):
sendErrorLog("jQuery error: " + message)
throw new Error(message)
Reference
Cheat Sheet
Keep these facts handy while throwing plugin errors with jQuery.
Check these before overriding or calling jQuery.error.
override
Always throw after logging
An override that only logs swallows failures. End with throw new Error(message).
ajax
Not an Ajax error API
Network / HTTP failures belong to ajaxError and .fail() — not $.error.
uncaught
Uncaught throws stop scripts
Without try/catch, the exception surfaces as an uncaught error. Catch when recovery is possible.
clarity
Prefer throw new Error in apps
Reserve $.error for the shared plugin hook. Everyday app code is clearer with a native throw.
Compatibility
Browser Support
jQuery.error() is available since jQuery 1.4.1+ in all modern browsers with jQuery loaded. It is a thin throw helper — not a browser API.
✓ jQuery 1.4.1+ · Stable
jQuery.error()
Works in Chrome, Firefox, Safari, and Edge whenever jQuery 1.4.1+ is loaded. Prefer throw new Error() in application code unless you need an overridable plugin hook.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
$.error()jQuery 1.4.1+
Bottom line: Use $.error(msg) as a shared plugin throw hook. Override only if you still throw afterward.
Analysis
Performance Notes
Approach
Cost
Best for
$.error(msg)
Throw path
Rare validation failures
throw new Error(msg)
Throw path
App code (clearer)
Logging override
I/O bound
Keep logging cheap; never block UI loops
Throwing is for exceptional cases, not normal control flow. Do not call $.error inside hot loops — validate early and cheaply.
Remember
Key Takeaways
Role:$.error(msg) throws with that message.
Override: log, then still throw new Error(msg).
Audience: plugin authors more than everyday app code.
One line:$.error is a throw helper you can override for logging — but you must still throw.
Frequently Asked Questions
jQuery.error(message) takes a string and throws an exception containing that message. It exists mainly so plugin authors can override it for custom reporting while still throwing. Available since jQuery 1.4.1.
Usually prefer throw new Error(message) for clarity. Use jQuery.error when you want one shared hook that plugins can override for centralized logging.
Assign a new function that logs (or updates UI), then still throw — typically throw new Error(message). The official docs warn: if you override, remember to throw at the end to preserve semantics.
It does not return normally — it throws. Control jumps to the nearest catch or to the browser’s uncaught-error path.
Yes. try { jQuery.error("boom"); } catch (e) { console.log(e.message); }. The caught value is typically an Error whose message is your string.
No. Ajax failures use .fail(), error callbacks, and ajaxError. jQuery.error is a small throw helper for plugins — a different API.