JavaScript AggregateError object Last Updated : 07 Jun, 2022 Comments Improve Suggest changes Like Article Like Report The JavaScript AggregateError object is used to reflect the overall error of many single errors. This can be used when multiple errors need to be represented in the form of a combined error, for example, it can be thrown by Promise.any() when all the promises passed to it are rejected. Construction: The constructor AggregateError() is used to create a new object of AggregateError. Instance Properties: This object has two properties: message: We use the AggregateError.prototype.message to display the message of error. The default error message shown is " ".name: We use the AggregateError.prototype.name to display the name of error. The default error name shown is AggregateError. Example 1: This example shows the catching of an AggregateError. JavaScript <script> Promise.any([ Promise.reject( new Error( "There is any error occurred" ) ), ]).catch(n => { // Check if AggregateError console.log( n instanceof AggregateError ); // Print the message of the error console.log(n.message); // Print the name of the error console.log(n.name); // Print all the errors that this // error comprises console.log(n.errors); } );</script> Output: true All promises were rejected AggregateError [Error: There is any error occurred] Example 2: This example shows the creating of an AggregateError. JavaScript <script> try { throw new AggregateError([ new Error( "This is Error 1" ), new Error( "This is Error 2" ), new Error( "This is Error 3" ), ], 'These are multiple errors'); } catch (n) { // Check if AggregateError console.log( n instanceof AggregateError ); // Print the message of the error console.log(n.message); // Print the name of the error console.log(n.name); // Print all the errors that this // error comprises console.log(n.errors); } </script> Output: true These are multiple errors AggregateError [Error: This is Error 1, Error: This is Error 2, Error: This is Error 3] Create Quiz Comment K krishnakripa Follow 0 Improve K krishnakripa Follow 0 Improve Article Tags : JavaScript Java Quiz Web Technologies javascript-object Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like