首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

URIError

URIError 对象用来表示以一种错误的方式使用全局URI处理函数而产生的错误。

语法

代码语言:javascript
复制
new URIError([message[, fileName[, lineNumber]]])

参数

message可选的。人类可读的错误描述fileName可选。包含导致异常的代码的文件的名称lineNumber可选。导致异常的代码的行号

描述

当全局URI处理函数传递格式不正确的URI时引发URIError.

属性

URIError.prototype允许将属性添加到URIError对象。

方法

全局URIError不包含自己的方法,但它通过原型链继承了一些方法。

URIError实例

属性

URIError.prototype.constructor指定创建实例原型的函数。

URIError.prototype.message错误信息。虽然ECMA-262规定URIError应该提供自己的message财产,在SpiderMonkey中,它继承Error.prototype.message

URIError.prototype.name错误名称。继承Error

URIError.prototype.fileName引发此错误的文件路径。继承Error

URIError.prototype.lineNumber引发此错误的文件中的行号。继承Error

URIError.prototype.columnNumber引发此错误的列号。继承Error

URIError.prototype.stack堆栈跟踪。继承Error

方法

尽管URIError原型对象本身不包含任何方法,但URIError实例通过原型链继承了一些方法。

示例

捕获一个?URIError 对象

代码语言:javascript
复制
try {
  decodeURIComponent('%');
} catch (e) {
  console.log(e instanceof URIError); // true
  console.log(e.message);             // "malformed URI sequence"
  console.log(e.name);                // "URIError"
  console.log(e.fileName);            // "Scratchpad/1"
  console.log(e.lineNumber);          // 2
  console.log(e.columnNumber);        // 2
  console.log(e.stack);               // "@Scratchpad/2:2:3\n"
}

创建一个?URIError对象

代码语言:javascript
复制
try {
  throw new URIError('Hello', 'someFile.js', 10);
} catch (e) {
  console.log(e instanceof URIError); // true
  console.log(e.message);             // "Hello"
  console.log(e.name);                // "URIError"
  console.log(e.fileName);            // "someFile.js"
  console.log(e.lineNumber);          // 10
  console.log(e.columnNumber);        // 0
  console.log(e.stack);               // "@Scratchpad/2:2:9\n"
}

规范

Specification

Status

Comment

ECMAScript 3rd Edition (ECMA-262)The definition of 'URIError' in that specification.

Standard

Initial definition

ECMAScript 5.1 (ECMA-262)The definition of 'URIError' in that specification.

Standard

?

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'URIError' in that specification.

Standard

?

ECMAScript Latest Draft (ECMA-262)The definition of 'URIError' in that specification.

Living Standard

?

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com