AggregateError() constructor

AggregateError() 생성자는 여러 오류를 하나의 오류로 포장하기 위한 오류를 생성합니다.

구문

new AggregateError(errors)
new AggregateError(errors, message)
new AggregateError(errors, message, options)

AggregateError(errors)
AggregateError(errors, message)
AggregateError(errors, message, options)

참고: AggregateError()new와 함께 혹은 없이도 호출할 수 있습니다. 두 방법 모두 AggregateError를 생성합니다.

매개변수

errors

반복 가능한 오류들. 실제 Error객체가 아닐 수 있습니다.

message Optional

AggregateError의 사람이 읽을 수 있는 설명입니다. 선택적 입력값입니다.

options Optional

다음 속성을 가진 객체입니다.

cause Optional

오류의 특정 원인을 나타내는 속성입니다. 보다 구체적이거나 유용한 오류 메시지로 오류를 잡아서 다시 오류를 발생시킬 때 이 속성을 사용하여 원래 오류를 전달할 수 있습니다.

예제

AggregateError 생성하기

try {
  throw new AggregateError([
    new Error("some error"),
  ], 'Hello');
} catch (e) {
  console.log(e instanceof AggregateError); // true
  console.log(e.message);                   // "Hello"
  console.log(e.name);                      // "AggregateError"
  console.log(e.errors);                    // [ Error: "some error" ]
}

명세서

Specification
ECMAScript Language Specification
# sec-aggregate-error-constructor

브라우저 호환성

BCD tables only load in the browser

같이 보기