Introduction to W3C Dom exception object domexception

Source: Internet
Author: User
ArticleDirectory
    • 1. What is domexception?
    • Ii. Compatibility of Dom exceptions
    • 3. Constant list
    • Iv. Final description

 

For more information, see sitepoint> reference> JavaScript> Dom core> domexception.

1. What is domexception?

DomexceptionIs the core object of W3C Dom.DomexceptionInterface indicates a processing error. If an operation cannot be executed, an exception is thrown. For example, you can try to create an invalid Dom or use a nonexistent node as the parameter node operation method.

For example, chestnut: Code :
 
VaR node = Document. getelementsbytagname ('h1 '). Item (0); var refnode = node. nextsibling; var newnode = Document. createtextnode (' that's why you got down! '); Node. insertbefore (newnode, refnode );

The code above demonstrates a fartInsertbeforeOperation, becauseRefnodeIt is not a subnode. In the Opera browser, the above operation will cause the following Exception error:

Inline script threaderror: unhandled exception: [object domexception] Code: 8 Message: not_found_err

Dom does not define an exception for each possible error, such as parameter or syntax error. In this case, it has its own error reporting mechanism to handle it.

In fact, most browsers have used DOM exceptions as a local mechanism. In addition to displaying the Exception Code and information, it also displays other information (such as the number of lines or stack tracks) that the browser can provide)

Ii. Compatibility of Dom exceptions

The compatibility is shown in the table below:

Internet Explorer firefox safari opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5

The Compatibility data in the table above is still relatively old. According to the general rules, ie9 should also support the latest Chrome browser.

The IE browser of archaeological value does not support this interface. They use local errors (such as parsing errors ). For example, in the example of inserting a node above, what is thrown in the old IE is:Invalid argument. In XML, more information is provided:Insert position node must be a child of the node to insert under.

3. Constant list

This interface definesPredictioncodeInteger-ExposureCodeAttribute -- points to errors of each type. For these definitions, refer to the following constants:

Index_size_err Code 1
If the index is a negative value or exceeds the allowed value. For example, the offset parameter of splittext is longer than the string length.
Domstring_size_err Code 2
The specific character data of domstring is too large. Its size display is implemented by dependency and is not defined by Dom (for details about the restrictions of Each browser, see Dom core ).
Hierarchy_request_err Code 3
A node cannot have a new subnode, or the new node is already the ancestor node of the node. For example, try to add the element node to the text node.
Wrong_document_err Code 4
Try to use cross-document nodes. For example, the child node of appendchild comes from other documents. Instead of outputting first (using importnode ).
Invalid_character_err Code 5
An invalid or invalid character specifies a restricted string, such as the element's Name.
No_data_allowed_err Code 6
Specify data for nodes that do not support data. If an element node does not contain data, its subnodes include data.
No_modification_allowed_err Code 7
An attempt is made to modify a node that cannot be modified. For example, load a read-only node.
Not_found_err Code 8
The referenced node does not exist. For example, InsertbeforeThe related subnode is not the referenced subnode.
Not_supported_err Code 9
The specified operation is not supported. For example, if a node method is used, but this method is not implemented, this error is thrown.
Inuse_attribute_err Code 10
Try to add an attribute in use. For example, use setattributenode to reference an ATTR that is already used in another element, instead of cloning it first (using clonenode ).
Invalid_state_err Code 11
Try to use an unavailable object. This error is usually thrown because methods cannot perform specific operations for some internal reasons.
Syntax_err Code 12
Invalid or invalid string is specified. For example, set it with invalid CSS values SelectortextAttribute Cssstylerule. // Zxx: this error is caused by <Title>Label used InnerhtmlMethod.
Invalid_modification_err Code 13
Try to modify the type of a node. For example, use a value that does not match the original rule type CsstextAttribute Cssrule. (For example, set the style-Rule values value for at-rule ).
Namespace_err Code 14
The operation conflicts with the namespace. For example, createelementns uses the name of the split Jujube.
Invalid_access_err Code 15
An attribute or operation does not support the specified node. For example, try to use GetfloatvalueOf CssprimitivevalueMethod.

About code:The integer value of predictioncode (that is, the code in the above list and then three) indicates the domexception type.

Iv. Final description

The content of this article has nothing to look. Important: Here is an article aboutDomexceptionYou can quickly find the article! The explanations for different values of predictioncode in the list shown above are too general. The following examples show methods and attributes. Therefore, there is still a gap between a vision inspired by everyone who wishes to come in. Domexception errors are also not easy to encounter. However, once a problem occurs, the Js of the entire page will basically be decommissioned, and the error is not easy to find. For example, using numbers as elementsIDIn some cases, the domexception error is reported in some browsers.

I am lazy now. If I used to graduate, when I was so passionate, I would forget to present every mistake. Now, alas, it cannot be done, and it is not easy to present errors. Sorry, you can only explain the general terms above.

However, unity is the power. This article can comment without limit. Therefore, if you encounter a domexception error and solve it here or there, remember to take the error code, the specific situation, and the solution. In the form of a comment or email (zhangxinxu@zhangxinxu.com), I will certainly sort it out and put it in the body. In this way, brainstorm and stream into the sea. In the future, once the browser reports a domexception error, you can do it here. Isn't that good.

Therefore, we hope that this article will become a platform to solve the domexception error and collect the experience of various peers to benefit ourselves and other peers. It is not just a common article. The idea is beautiful. It depends on your contribution and support! Work together!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.