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 JavaScript AggregateError object 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: 2 min read JavaScript Errors Throw and Try to Catch JavaScript uses throw to create custom errors and try...catch to handle them, preventing the program from crashing. The finally block ensures that code runs after error handling, regardless of success or failure.throw: Used to create custom errors and stop code execution.try...catch: Allows you to c 3 min read JavaScript EvalError Object There are several types of errors that we encounter in JavaScript, for example, SyntaxError, RangeError, ReferenceError, EvalError, etc. The EvalError indicates an error regarding the global eval() function. Newer versions of JavaScript however do not throw EvalError. Syntax: new EvalError()new Eval 1 min read JavaScript Error Object Complete Reference Error objects are arising at runtime errors. The error object also uses as the base object for the exceptions defined by the user. The complete list of JavaScript Error Object properties are listed below: Error types JavaScript RangeError â Invalid dateJavaScript RangeError â Repeat count must be no 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 Javascript Error and Exceptional Handling In JavaScript, error and exception handling allows you to manage unexpected issues that occur during the execution of your code. By using tools like try, catch, throw, and finally, you can handle errors easily and prevent the program from crashing. This enables you to provide meaningful error messag 6 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