Tutorial by Examples

new Error(message) Creates new error object, where the value message is being set to message property of the created object. Usually the message arguments are being passed to Error constructor as a string. However if the message argument is object not a string then Error constructor calls .toString...
Throwing error means exception if any exception is not handled then the node server will crash. The following line throws error: throw new Error("Some error occurred"); or var err = new Error("Some error occurred"); throw err; or throw "Some error occurred";...
try...catch block is for handling exceptions, remember exception means the thrown error not the error. try { var a = 1; b++; //this will cause an error because be is undefined console.log(b); //this line will not be executed } catch (error) { console.log(error); //here we handl...

Page 1 of 1