最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firefox - "throw" a warning in JavaScript? - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论