可选stack静态stackError.stackTraceLimit 指定堆栈追踪采集的帧数,适用于 new Error().stack 和 Error.captureStackTrace(obj)。
默认值为 10,也可设为任意有效的 JavaScript 数值。修改仅影响修改之后采集的堆栈追踪。
设为非数值或负数时,堆栈追踪不采集任何帧。
静态capture在 targetObject 上创建 .stack 属性。访问该属性时,返回描述调用 Error.captureStackTrace() 所在代码位置的字符串。
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`
堆栈首行以 ${myObject.name}: ${myObject.message} 为前缀。
可选参数 constructorOpt 接受一个函数。指定后,生成的堆栈会省略 constructorOpt 之上的所有帧,也包括 constructorOpt 本身。
constructorOpt 可用于向用户隐藏错误生成的实现细节,例如:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
targetObjectconstructorOpt可选静态prepareerrstackTraces
SFML 绑定报告的运行时错误。