Generating Errors to Test Error Handling

You can test the ways your program responds to run-time errors by causing them on purpose:

■ Generate any built-in error by entering the following syntax: Error error_number

For example, to display the error that occurs on an attempt to divide by zero (0), type the following statement in the Immediate window:

Error 11

When you press Enter, Visual Basic will display the error message saying, "Run-time error 11. Division by zero."

Part I

To check the meaning of the generated error, use the following syntax: Error(error_number)

For example, to find out what error number 7 means, type the following in the Immediate window:

When you press Enter, Visual Basic returns the error description: "Out of memory"

0 0

Post a comment