Open In App

HTML DOMException message Property

Improve
Improve
Like Article
Like
Save
Share
Report

The DOMException message property returns a DOMString representing a message or description associated with the given error. This is a read-only property.

Syntax:

domException.message

Return Value: This property returns a DOMString associated with an error.

Example: This example illustrates the use of DOMException message property.

HTML




<!DOCTYPE html>
<html>
 
<body>
    <h1>GeeksforGeeks</h1>
 
     
     
<p>
        Click below to get
        the exception message
    </p>
 
 
 
    <button onclick="get()">Click</button>
 
    <p class="p">Error Message is : </p>
 
 
 
    <script>
        function get() {
            try {
                // INVALID_CHARACTER_ERR
                var elem = document
                    .createAttribute("123");
            }
            catch (e) {
                document.querySelector(".p")
                    .textContent += e.message;
            }
        }
    </script>
</body>
 
</html>


Output:

Before Clicking the Button:

After Clicking the Button:

Supported Browsers: 

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Internet Explorer 9
  • Safari 1
  • Opera 12.1

Last Updated : 06 Jul, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads