admin管理员组

文章数量:1326093

In FireFox, there is this cute little Error-Console [Ctrl+Shift+J] where I can add an error by throwing it from JavaScript. Is there a way to display a warning or a message, too? I dont mean console.warn(), i really want it in the error-console, i'd just prefer to have it a warning mark instead of an error marking.

Is there a way to acplish this?

In FireFox, there is this cute little Error-Console [Ctrl+Shift+J] where I can add an error by throwing it from JavaScript. Is there a way to display a warning or a message, too? I dont mean console.warn(), i really want it in the error-console, i'd just prefer to have it a warning mark instead of an error marking.

Is there a way to acplish this?

Share Improve this question asked Jan 13, 2013 at 22:51 rhavinrhavin 1,6971 gold badge14 silver badges33 bronze badges 4
  • Is this for a webpage or a Firefox plugin? – Felix Kling Commented Jan 13, 2013 at 22:52
  • If you've got Firebug installed there's a console.warn(). – Pointy Commented Jan 13, 2013 at 22:52
  • 1 webpage. @Pointy: did u read my question…? – rhavin Commented Jan 13, 2013 at 22:53
  • Ah OK, sorry. I misunderstood what you meant by that reference to console.warn(). – Pointy Commented Jan 13, 2013 at 23:03
Add a ment  | 

2 Answers 2

Reset to default 11

There is no such thing as a Warning in JavaScript. All errors are fatal.

console.warn will, in browsers that implement it, print a warning-level message in the console (similar to malformed HTML or security warnings).

Personally, I'd just write console.log("Warning: It's late and I'm drunk.");

JavaScript has a number of built-in error constructors, such as Error(), SyntaxError(), and TypeError(), and others, which are used with the throw statement. These objects contain interesting information about the error such as the name property of the constructor function that created the object, or the message that was passed in to the object.

The fun part about JavaScript is that you can throw any objects you want. So based on this concept, you can do something like throw {name: "some name", message: "some message", remedy: callback}, catch this error in a top level try/catch statement and output the contents using console.log.

Hope this helps.

本文标签: firefoxquotthrowquot a warning in JavaScriptStack Overflow