Error : Object
An object thrown when an error occurs.
There are several specific constructor functions for different types of
error conditions:
**EvalError**,
**RangeError**,
**ReferenceError**,
**SyntaxError**,
**TypeError**,
**URIError**,
**NativeError**.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11
----
Error(message : String) : Error
Same as %%#new_Error_String|**new Error(message)**%%.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.1.1
----
new Error(message : String) : Error
Creates a new **Error** with the specified **message** that describes the error.
var divide = function(x, y) {
if (y === 0) {
throw new Error('divide by zero');
}
return x / y;
};
try {
console.log(divide(10, 0));
}
catch (error) {
console.log(error.name);
console.log(error.message);
}
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.2.1
----
prototype.name : String
The type of error.
try {
foo;
}
catch (error) {
console.log(error.name);
}
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.4.2
----
prototype.message : String
A human readable message that describes the error.
try {
foo;
}
catch (error) {
console.log(error.message);
}
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.4.3