VB.net's error handling

Source: Internet
Author: User
Tags exit error handling expression goto

Error handling in vb.net is implemented using the excetions instead of the On Error Goto syntax, and the On Error Goto is now not supported, and Visual Basic now provides a structured error-handling process that uses a try ... Catch... Finally expression. A structured error-handling process is related to exceptions, similar to a Select Case or a while, a code structure with a selection relationship. This makes the code of the program more robust and allows for more complex error handling. The operating mechanism of exceptions is such that, when there are errors, the error handling process is blocked, causing the error in the try module to run the code, and using the catch expression to get the error, the syntax is as follows:

First, run the code in the try module, run the code in the finally module if there is no error, run the code in the catch module if there is a mistake, and the user can make some error handling in the Catch module. Then run the code in the finally module and exit the entire module.
The following example shows how to make error handling settings, when the user accesses an array list, after the length of the list, an error occurs, the code is as follows:

The example above prints out the error message and indicates where the code has been wrong and continues to run. The following is the result of the run:

Conversely, if the user does not make error handling, it will get the wrong information from the system at run time, and exit the running environment directly, instead of continuing to run. The system will receive the following error message:

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.