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 Difference between the Constructors and Methods Java is a pure OOPS concept based programming language. Hence in Java, all the variables, data and the statements must be present in classes. These classes consist of both constructors and methods. Methods and Constructors are different from each other in a lot of ways. Constructors: Constructors ar 3 min read The 'new' operator in Javascript for Error Handling In this article, we will see new operator usage during error throwing as well as handling the error() method in JavaScript using theoretical as well as coding examples. JavaScript new operator: The new operator is actually a special operator that is used along with the error() method which is the me 3 min read How to Solve Class Cast Exceptions in Java? An unexcepted, unwanted event that disturbed the normal flow of a program is called Exception. Most of the time exceptions are caused by our program and these are recoverable. Example: If our program requirement is to read data from the remote file locating at the U.S.A. At runtime, if the remote fi 3 min read java.nio.charset.CodingErrorAction Class in Java In Java programming, Character encoding plays an important when we talk about handling data and information across different systems. The java.nio.charset package contains classes for managing character encoding and decoding. CodingErrorAction class is one of the package's core classes. This class d 2 min read How to Resolve Java.lang.ExceptionInInitializerError In Java? An unexpected, unwanted event that disturbed the normal flow of a program is called an Exception. There are mainly two types of exception in Java: 1. Checked Exception 2. Unchecked Exception ExceptionInInitializerError is the child class of the Error class and hence it is an unchecked exception. Thi 3 min read Like