URIError

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

Đối tượng URIError biểu diễn một lỗi khi một hàm xử lý URI toàn cục được sử dụng theo cách sai.

URIError là một serializable object, vì vậy nó có thể được nhân bản với structuredClone() hoặc sao chép giữa các Worker bằng cách sử dụng postMessage().

URIError là lớp con của Error.

Constructor

URIError()

Tạo một đối tượng URIError mới.

Thuộc tính instance

Cũng kế thừa các thuộc tính instance từ lớp cha Error.

Các thuộc tính này được định nghĩa trên URIError.prototype và được chia sẻ bởi tất cả các instance URIError.

URIError.prototype.constructor

Hàm constructor đã tạo ra đối tượng instance. Đối với các instance URIError, giá trị khởi tạo là constructor URIError.

URIError.prototype.name

Đại diện cho tên của loại lỗi. Đối với URIError.prototype.name, giá trị khởi tạo là "URIError".

Phương thức instance

Kế thừa các phương thức instance từ lớp cha Error.

Ví dụ

Bắt một URIError

js
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.stack); // Stack of the error
}

Tạo một URIError

js
try {
  throw new URIError("Hello");
} catch (e) {
  console.log(e instanceof URIError); // true
  console.log(e.message); // "Hello"
  console.log(e.name); // "URIError"
  console.log(e.stack); // Stack of the error
}

Đặc tả kỹ thuật

Specification
ECMAScript® 2027 Language Specification
# sec-native-error-types-used-in-this-standard-urierror

Tương thích trình duyệt

Xem thêm