InternalError

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

Đối tượng InternalError chỉ ra một lỗi xảy ra bên trong JavaScript engine.

Các trường hợp ví dụ thường xảy ra khi điều gì đó quá lớn, chẳng hạn:

  • "too many switch cases" (quá nhiều case trong switch),
  • "too many parentheses in regular expression" (quá nhiều dấu ngoặc đơn trong biểu thức chính quy),
  • "array initializer too large" (bộ khởi tạo mảng quá lớn),
  • "too much recursion" (quá nhiều đệ quy).

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

Constructor

InternalError() Non-standard

Tạo một đối tượng InternalError 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 InternalError.prototype và được chia sẻ bởi tất cả các instance InternalError.

InternalError.prototype.constructor

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

InternalError.prototype.name

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

Phương thức instance

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

Ví dụ

Quá nhiều đệ quy

Hàm đệ quy này chạy 10 lần, theo điều kiện thoát.

js
function loop(x) {
  // "x >= 10" is the exit condition
  if (x >= 10) return;

  // do stuff
  loop(x + 1); // the recursive call
}
loop(0);

Đặt điều kiện này thành một giá trị cực kỳ lớn có thể không hoạt động:

js
function loop(x) {
  if (x >= 1000000000000) return;

  // do stuff
  loop(x + 1);
}
loop(0);

// InternalError: too much recursion

Để biết thêm thông tin, xem InternalError: too much recursion.

Đặc tả kỹ thuật

Không thuộc bất kỳ tiêu chuẩn nào.

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

Xem thêm