JavaScript advanced programming Reading Notes (20) js error handling _ javascript skills

Source: Internet
Author: User
Syntax errors, also known as parsing errors, occur in the compilation of traditional languages, occur in the interpretation of JavaScript, and runtime errors are also known as exceptions (exception, after the interpreter during compilation) I. Error Classification

1. syntax error: it is also called a parsing error. It occurs during compilation in traditional languages and occurs in JavaScript during interpretation. These errors are directly caused by unexpected characters in the Code and cannot be directly compiled/interpreted. When a syntax error occurs, the Code cannot be executed. In JavaScript, only the code in the same thread is affected by syntax errors. Code in other threads and other externally referenced files can be executed if it does not depend on the code that contains the error.
2. runtime error: Also known as exception (exception, after the compilation/Interpreter ). At this point, the problem is not in the code syntax, but an operation that is attempted, in some cases, illegal. Exceptions only affect the threads that occur. Other JavaScript threads can continue normal execution.

Ii. Error Handling


JavaScript provides two methods to handle errors: The onerror event processing function in BOM and the try... catch Method in ECMAScript.
1. onerror event processing functions
It is the first mechanism to assist JavaScript in error handling. When an exception occurs on the page, the error event is triggered on the window object. For example:

The Code is as follows:




Onerror Example

Related Article

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.