admin管理员组文章数量:1325538
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
2 Answers
Reset to default 11There 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
版权声明:本文标题:firefox - "throw" a warning in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742194244a2430781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论