pimvdb pimvdb - 6 months ago 25x
Javascript Question

"throw new Warning" in JavaScript?

At the moment I'm extending my JavaScript project with error handling. The

statement is playing an important role here:

throw new Error("text"); // Error: text

However, can I also throw a warning? I tried the following to no avail:

throw new Warning("text"); // Warning is not defined

The errors make Chrome's Developer Tools show a red cross, but how can I make it display a warning icon (yellow exclamation mark)?


Like this:


Note that unlike exceptions, this will not interrupt your code; the calling function will continue normally.

Also note that this will throw an error in any browser except for WebKits or Firefox with Firebug, because console won't exist.

To fix that, you can include Firebug Lite, or make a fake NOP-ing console object.