JQuery could throw nicer errors

JQuery could throw nicer errors


Hello!
I've been using this brilliant library now for quite a while. It's
been all good, I've just noticed one draw back that can make JQuery
hard to debug when things don't go right. Sometimes the errors in the
browser's error console are meaningless, and sometimes no error is
thrown at all despite an obvious mistake.
Take these examples:
"$(true).html()" - Throws a TypeError with the information 'this
[0].innerHTML is undefined
Source File: query-1.3.2.min.js Line: 12'
"$("p").html(true)" - Reduces the HTML of all <P> elements to nothing.
It can be passed objects too, and the same behaviour is observed.
There are many more examples. It can be easy to accidentally make a
silly mistake like these, especially if the mistakes are hidden in
dynamic variables somewhere else in the code. If you're dealing with a
large code it can be like searching for a needle in a hey stack.
Messages can be thrown to the browser's console like this:
throw new Error("JQuery: My error"); //It seems that all ' should
be escaped to \' for IE
I think coding a debug message for every possible scenario would be
too much extra work and would increase the size of jquery. Perhaps it
could still be useful to have debugging output for the most commonly
used methods. Either way, it might also be useful to have a
jQuery.fn.error function (e.g. jQuery.fn.error("My error message and
details") might output "JQuery: My error message and details") so that
plug in developers can throw nice errors.