• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • WebAssembly.RuntimeError()

    WebAssembly.RuntimeError()构造函数创建一个新的 WebAssembly RuntimeError 对象---一个每当 WebAssembly 陷入指定陷阱时将抛出的类型。

    语法

    new WebAssembly.RuntimeError(message, fileName, lineNumber)
    

    参数

    message可选

    有可读性的错误信息。

    fileName可选非标准

    包含导致异常的代码的文件名。

    lineNumber可选非标准

    导致异常的代码的行号。


    属性

    RuntimeError构造函数不包含其自身特有的属性,但是,它确实通过原型链继承了某些属性。

    WebAssembly.RuntimeError.prototype.constructor

    创建示例原型的特定函数。

    WebAssembly.RuntimeError.prototype.message

    错误信息。尽管 ECMA-262 指定URIError应提供自己的message属性,但在SpiderMonkey中,它继承了Error.prototype.message

    WebAssembly.RuntimeError.prototype.name

    错误名称。继承自Error.

    WebAssembly.RuntimeError.prototype.fileName

    报出错误的文件路径。继承自Error.

    WebAssembly.RuntimeError.prototype.lineNumber

    报出错误的代码所在文件中的行数。继承自Error.

    WebAssembly.RuntimeError.prototype.columnNumber

    报出错误的代码所在文件中的列数。继承自Error.

    WebAssembly.RuntimeError.prototype.stack

    堆栈跟踪。继承自Error.


    方法

    RuntimeError构造函数不包含自己的方法,但是,它确实通过原型链继承了一些方法。

    WebAssembly.RuntimeError.prototype.toSource()

    返回可能导致相同错误的代码。继承自Error.

    WebAssembly.RuntimeError.prototype.toString()

    返回表示代表指定的Error对象的字符串。从Error.


    样例

    以下代码段创建了一个新的 RuntimeError 实例,并将其详细信息记录到控制台:

    try {
      throw new WebAssembly.RuntimeError('Hello', 'someFile', 10);
    } catch (e) {
      console.log(e instanceof RuntimeError); // true
      console.log(e.message);                 // "Hello"
      console.log(e.name);                    // "RuntimeError"
      console.log(e.fileName);                // "someFile"
      console.log(e.lineNumber);              // 10
      console.log(e.columnNumber);            // 0
      console.log(e.stack);                   // 返回代码运行的位置
    }