throw错误和console.error有什么区别 [英] What is the difference between throw Error and console.error
问题描述
这两个陈述之间有什么区别,是否有充分理由使用其中一个?
What is the difference between these two statements, and is there a good reason to use one over the other?
throw Error("msg");
console.error("msg");
在我有限的经验中,我只是真的看到抛出错误()
使用。有什么特别的原因吗?
In my limited experience, I've only really seen throw Error()
used. Is there any particular reason why?
此外,是否有相同的 console.warn()
时尚?
Also, is there an equivalent to console.warn()
in the same fashion?
推荐答案
throw ...
引发当前的异常代码块并导致它退出,或者如果在 try
块中引发,则流向下一个 catch
语句。
throw ...
raises an exception in the current code block and causes it to exit, or to flow to next catch
statement if raised in a try
block.
console.error
只是向浏览器开发人员工具javascript控制台输出一条红色消息,并且不会导致任何更改执行流程。
console.error
just prints out a red message to the browser developer tools javascript console and does not cause any changes of the execution flow.
这篇关于throw错误和console.error有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!