当我查找 javascript 错误类型时,我发现有 7 种错误类型,如 MDN 。
我可以生成所有核心五个错误,例如 SyntaxError
、ReferenceError
、RangeError
、URIError
和 TypeError
.
但是,我找不到生成其他 2 种错误类型 EvalError
和 InternalError
的方法。我如何生成这个? (或者)是否有任何示例 javascript 代码会引发此错误?
最佳答案
来自 ES5 specification :
15.11.6.1 EvalError
This exception is not currently used within this specification. This object remains for compatibility with previous editions of this specification.
所以我猜这个错误在现代浏览器中不会产生。
关于InternalError
,您链接到的页面显示:
InternalError
Creates an instance representing an error that occurs when an internal error in the JavaScript engine is thrown. E.g. "too much recursion".
确实,运行
function foo() {
foo();
}
foo();
抛出
InternalError: too much recursion
关于javascript - 引发 EvalError 和 InternalError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26258583/