JavaScript Error() constructor Last Updated : 07 Jul, 2022 Comments Improve Suggest changes Like Article Like Report Javascript Error() constructor is used to create a new error object. Error objects are arising at runtime errors. The error object also uses as the base object for the exceptions defined by the user. Syntax: new Error([message[, fileName[, lineNumber]]]) Parameters: message: It contains information about this error object which is in human-readable form. An error message can be set using javascript Error message property. It is an optional parameter.fileName: It is the name of the file for this error object. If no name is provided than fileName is equal to the name of file containing the code that called the Error() constructor. It is an optional parameter.lineNumber: It is the value for the lineNumber property on the created Error object. If no number is provided Than the lineNumber is equal to the line number containing the Error() constructor invocation. It is an optional parameter. Example 1: Creating error object using new keyword. JavaScript <script> try { const error = new Error('This object is created using new keyword') document.write("Error object created successfully using new keyword"); } catch(err) { document.write(err.message); } </script> Output: Error object created successfully using new keyword Example 2: Creating error object using function call. JavaScript <script> try { const error = Error('This is created is using function call') document.write("Error object created successfully using function call"); } catch(err) { document.write(err.message); } </script> Output: Error object created successfully using function call Supported Browsers: Google ChromeFirefoxEdgeInternet ExplorerOperaSafari Comment More infoAdvertise with us Next Article JavaScript Error() constructor A abhinavjain194 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Errors Similar Reads How to create custom errors in JavaScript ? In this article, we will learn to create custom errors with some examples. Errors represent the state of being wrong in condition. Javascript handles a predefined set of errors by itself but if you want to create your own error handling mechanism you can do that with custom errors functionality avai 2 min read What is Constructor? A constructor is a special type of method used in object-oriented programming languages to initialize objects. The constructor is called automatically every time when an object is created, allowing the object to set initial values for its attributes or perform other setup tasks.In this article, we w 3 min read Constructor in Java Abstract Class Constructor is always called by its class name in a class itself. A constructor is used to initialize an object not to build the object. As we all know abstract classes also do have a constructor. So if we do not define any constructor inside the abstract class then JVM (Java Virtual Machine) will g 4 min read java.lang.reflect.Constructor Class in Java java.lang.reflect.Constructor class is used to manage the constructor metadata like the name of the constructors, parameter types of constructors, and access modifiers of the constructors. We can inspect the constructors of classes and instantiate objects at runtime. The Constructor[] array will hav 4 min read Difference Between Constructor and Static Factory Method in Java Whenever we are creating an object some piece of code will be executed to perform initialization of that object. This piece of code is nothing but a constructor, hence the main purpose of the constructor is to perform initialization of an object but not to create an object. Let us go through the bas 4 min read Like