"JavaScript programming lecture" Reading Notes-Chapter 4 error handling

Source: Internet
Author: User

4.1

This chapter has a few pages and is dominated by text descriptions. You can write them where you want to use them.

First of all, JavaScript is a language that seldom complains about. In many cases, no matter whether it is good or bad, it will accept and will not report errors. We will have a headache During the error check. For example, function parameters can be variable, and almost any number of parameters can be received, and the types are not fixed. The type you want to pass in is an integer, but when you call it, you intentionally pass two character types, which will be silently tolerated and will not sound.

The simplest error is a syntax error. Powerful IDE can solve this problem (recommended: webstorm ). There are also runtime errors, which I don't know much about, such as memory, network, CPU and other errors. Other errors are caused by the programmer's inconsiderate consideration. I have read a JS book and the jsdom programming art before. They all say this book is good. I found that the code in this book has a characteristic of various judgments, thinking is quite meticulous. Therefore, when you think about more situations, you can minimize the number of errors.

4.2 exceptions

The basic usage of exceptions. You don't need to talk about it more. You can understand it after reading the code.

 function lastElement(array) {     if (array.length > 0) {     return array[array.length - 1];     } else {        throw "cant get the return result";     } } function lastElementPlusTen(array) { return lastElement(array) + 10; } try{ document.write(lastElementPlusTen([])); } catch(error){ document.write("the error is: "+error); } var currentThings = "success"; function pressThing(things) { var tempThings = currentThings; try { currentThings = "too much operate: " + things; } finally { currentThings = tempThings; } } pressThing(1000); document.write(currentThings); try{    throw new Error("i am a error"); } catch(error) {    document.write(error); }

 

 

 

 

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.