JS catch exception and throw exception

Source: Internet
Author: User

The TRY statement tests the code block for errors.

The catch statement handles the error.

The throw statement creates a custom error.

Mistakes are bound to happen.

When the JavaScript engine executes JavaScript code, various errors occur:

It could be a syntax error, usually a coding error or typo caused by a programmer.

It may be a misspelling or a missing feature in the language (possibly due to browser differences).

The error may be caused by error output from the server or user.

Of course, it may also be due to many other unpredictable factors.

When an error occurs, the JavaScript engine usually stops and generates an error message when something goes wrong.

The technical term that describes this situation is that JavaScript throws an error.

Try  {  //Run code here  }catch (err)  {  //Handle error here  }


///////////////////////////////

The throw statement allows us to create custom errors. An exception is thrown in the error-first callback function in the Nodejs of a single thread.

The correct technical term is: Create or throw an exception (exception).

If you use throw with try and catch, you can control the flow and generate custom error messages.

JS catch exception and throw exception

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.