Section 123th, javascript error handling and debugging

Source: Internet
Author: User

JavaScript Error handling and debugging

Learning Essentials:

1. Browser Error Reporting

2. Error handling

3. Error events

4. Error handling Policy

5. Commissioning Technology

6. Debugging Tools

JavaScript has always been a soft rib in error-handling debugging, and if the script goes wrong, the hints given often make people feel confused. ECMAScript the 3rd edition introduces Try...catch and throw statements and some error types to solve this problem, allowing developers to handle errors more appropriately.

A. Browser Error Reporting

As browsers continue to evolve, the ability to debug JavaScript code is becoming stronger. Browsers such as IE, Firefox, Safari, Chrome, and opera all have a mechanism for reporting JavaScript errors. However, browsers typically target ordinary users, which by default hide this type of information.

IE: By default, an error report appears in the lower left corner, and you can double-click the icon to see the Error message dialog box. If disable script debugging is turned on, an error box will pop up when an error occurs. The Setup method is: Tool->internet options, advanced, disable script debugging, uncheck it.

Firefox: By default, errors are not prompted by the browser. But in the background the error console can be viewed. Check the method: Tools->[web Developer]->web Console | Error console. In addition to the browser's own, the developer provides Firefox with a powerful plugin: Firebug. It can not only prompt errors, but also debug JavaScript and CSS, DOM, network link errors and so on.

Safari: By default, errors are not prompted by the browser. So, we need to open it. View by: Show menu bar, edit, preferences, advanced, show Web inspector, development-in menu bar | Displays the error controller.

Opera: By default, errors are hidden. Error logging is turned on by displaying the error console, developer tools, menu bar, view.

Chrome: By default, errors are hidden. Open the Error Record as: Tool->javascript console.

Two Error handling

A good error handling mechanism can prompt users to know what's going on without panicking. To do this, as a developer, we have to understand what means and tools are available to handle JavaScript errors.

Try-catch statements

ECMA262 version 3rd introduced the Try-catch statement as a standard way to handle exceptions in JavaScript.

Try to execute the code contained in the try

Catch if there is an error, execute catch, you can receive a parameter e,e is an exception object

Section 123th, javascript error handling and debugging

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.