message Property (Error) (JavaScript)

Returns an error message string.

Syntax


errorObj.message  

Parameters

errorObj
Required. Instance of Error object.

Remarks

The message property returns a string that contains an error message associated with a specific error.

The description and message properties provide the same functionality. The description property provides backwards compatibility; the message property complies with the ECMA standard.

Example

The following example causes a TypeError exception to be thrown and displays the name of the error and its message.

try  
{  
    // Cause an error.  
    var x = y;  
}  
catch(e)  
{  
    document.write ("Error Message: " + e.message);  
    document.write ("<br />");  
    document.write ("Error Code: ");  
    document.write (e.number & 0xFFFF)  
    document.write ("<br />");  
    document.write ("Error Name: " + e.name);  
}  

Example

The output of this code is as follows.

Error Message: 'y' is undefined  
Error Code: 5009  
Error Name: TypeError  

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: Error Object

See Also

description Property (Error)
name Property (Error)