Try-catch-finally in Javascript

Source: Internet
Author: User
Tags try catch

This morning, JS scripts are always written with errors, but I guarantee that there is no problem with the lines prompted, because the line is <input id = "button1" type = "button" value = "button" name = "button1" onclick = "getdiv ()">, how can it go wrong! The error message is that the row has a missing object! Why? I decided it was definitely not an error in this line of statements. I began to analyze the getdiv function. I want to use try-catch to catch it. I will use try catch statements in Js, I used it like this.

Try

{

}

Catch

{

}

// It takes a long time to use C # and does not look at the JS reference. Therefore, it is wrong to follow its ideas.

I checked the JScript reference later, and it specified this for try catch.

Try {
Trystatements

}
Catch (Exception)

{
Catchstatements

}
Finally

{
Finallystatements

}

Parameters

Trystatement

Required. An error may occur.

Exception

Optional. Any variable name.ExceptionThe initialization value of is the thrown error value.

Catchstatement

Optional. Processing in the associatedTrystatement.

Finallystatements

Optional. The statements that are unconditionally executed after all other processes occur.

 

However, an error occurs when I remove catchstatement. If I remove Finally, there is no problem.

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.