In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Break and Continue statements in the JavaScript cycle, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
JavaScript errors-Throw, Try, and Catch
The try statement tests for errors in the code block. The catch statement handles errors. The throw statement creates a custom error.
Mistakes are bound to happen.
When the JavaScript engine executes JavaScript code, various errors occur:
It can be a syntax error, usually a coding error or typos caused by a programmer.
It may be a spelling mistake or a missing feature in the language (may be due to browser differences).
It may be an error caused by an incorrect output from the server or the user.
Of course, it may also be due to many other unpredictable factors.
JavaScript threw an error
When an error occurs, the JavaScript engine usually stops and generates an error message.
The technical term to describe this situation is: JavaScript will throw an error.
JavaScript Test and capture
The try statement allows us to define blocks of code that are tested for errors at execution time.
The catch statement allows us to define the block of code to execute when an error occurs in the block of try code.
The JavaScript statements try and catch appear in pairs. The syntax is as follows:
Try {/ / run the code here} catch (err) {/ / handle errors here
Tip: in this example, the catch block catches the error in the try block and executes the code to handle it:
Var txt= "; function message () {try {alerts (" Welcome guest! ");} catch (err) {txt=" there is an error on this page. \ n\ n "; txt+=" error description: "+ err.message +"\ n\ n "; click OK to continue. \ n\ n "; alert (txt);}} Test input value
Tip: this example detects the value of the input variable. If the value is wrong, an exception (error) is thrown.
Catch catches the error and displays a custom error message, such as too big, too small, and so on.
In addition, if the getElementById function goes wrong, the above example will also throw an error.
Thank you for reading this article carefully. I hope the article "how to use Break and Continue sentences in JavaScript Loop" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.