Chapter 6 of [database programming standard and specification series]: Error Handling

Source: Internet
Author: User
6.1 Overview when creating each process, it should be assumed that it may have an error (1) Error Source: programmer environment (Disk Space) time (not loaded) (2) Error classification: 1. Compile For example: PublicsubMyProcedure (intMyVariableAsInteger) Call: CallMyProcedure (invVariable1,

6.1 Overview when creating each process, it should be assumed that it may have an error (1) Error Source: programmer environment (Disk Space) time (not loaded) (2) Error classification: 1. Compile For example: Define: Public sub MyProcedure (intMyVariable As Integer) Call: CallMyProcedure (invVariable1,

6.1 Overview

When creating each process, it should be assumed that it may have an error

(1) Error Source:

Programmer

Environment (disk space)

Time (not loaded)

(2) Error classification:

1. Compile

For example:

Definition: Public sub MyProcedure (intMyVariable As Integer)

Call: Call MyProcedure (invVariable1, intVariable2)

2. runtime:

The result of an attempt to perform an invalid operation on the variable.

Print 10/intMyVariable

(3) Objective: To create an error handling program to prevent program running from being interrupted.

Visual Basic compilation options

(1) One configuration item is "Compile On Demand)

Start/F5 and compile only the Code required to run the application

Compile hidden errors when removing requests:

Disable "compile upon request" and run it. Force VB to check the entire application to find out the compilation error.

Generate executable files for the project. Force VB to check the entire application to find out the compilation error.

Run -- full compilation and execution; press Ctrl + F5

(2) One configuration item is Background Compile)

Compilation of processes and modules when referenced; compilation of unreferenced modules at leisure, with compilation errors kept at the lowest level

6.2 Err Object

The Raise method of the Err Object will cause an error and form the attributes of the Err Object.

6.3 error handling program type

After an error is captured, the error message is not displayed, and the code is not terminated.

Capture errors

OnError statement, located in the first line, placed immediately behind the process title and before the variable description.

Two methods:

OnError GoTo, which is transferred to the specified code for execution.

The OnError Resume Next statement ignores code errors and skips execution.

A runtime error, for example:


Test the Err Object at any time, for example:


Uppercase letters should be used for all annotations.


To ensure that the error handler is executed only when an error occurs, add the ExitSub, Exit Function, or Exit Property statement before the error handler.


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.