homecode zoneQuick Codedownloadssubmit codeabout usfeedbackscontact ussitemap
 
Beginners
Database
File System Object
General
Graphics
Multimedia
Networking
Shell Object
Timer
Array
Date/Time
Declaration
Error Handling
File/Folder
Logic
Loops & Conditional
Math
Miscellaneous
Strings
Values
Pro - Languages
C/C++
Java
Visual basic
asp
vb.net 2003/2005
asp.net
Quick Code
SUBMIT CODE
Mail List
LINKS
Submit LINK
 
ProgrammerGuide.net - VB Error Handling.
Home » VB Zone » Error Handling

On Error Statement

Enables an error-handling routine and specifies the location of the routine within a procedure; can also be used
to disable an error-handling routine.

Syntax
On Error GoTo line
On Error Resume Next
On Error GoTo 0

The On Error statement syntax can have any of the following forms:

Statement Description
On Error GoTo line Enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement Otherwise, a compile-time error occurs.
   
On Error Resume Next Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.
   
On Error GoTo 0 Disables any enabled error handler in the current procedure.


Remarks :
If you don't use an On Error statement, any run-time error that occurs is fatal; that is, an error message is
displayed and execution stops.

Resume, Resume Next, Resume Line ()

Resumes execution after an error-handling routine is finished.

Syntax
Resume [0]
Resume Next
Resume line

The Resume statement syntax can have any of the following forms:

Statement  Description
Resume If the error occurred in the same procedure as the error handler, execution resumes with the statement that caused the error. If the error occurred in a called procedure,execution resumes at the statement that last called out of the procedure containing the
   
Resume Next If the error occurred in the same procedure as the error handler, execution with the statement immediately following the statement that caused the error. If the error occurred in a called procedure, execution resumes with the statement immediately following the statement that last called out of the
   
Resume line Execution resumes at line specified in the required line argument. The line argument is a line label or line number and must be in the same procedure as the error handler


Remarks :
If you use a Resume statement anywhere except in an error-handling routine, an error occurs.

Example:
Private Sub
On Error GoTo Error
End Sub
Error:
Resume

Error Function

Simulates the occurrence of an error.

Syntax: Error errornumber
The required errornumber can be any valid error number.

Remarks
The Error statement is supported for backward compatibility. In new code, especially when creating objects, use the Err object's Raise method to generate run-time errors.

« Previous 1 2 Next »

Viewers: 8
Visitors:71402
Last Updated on:Sunday, January 17, 2010
Home | About us | Feedback | Contact us | Sitemap
Copyright © 2008 ProgrammerGuide.net. All rights reserved.
This site is best viewed in IE 6.0, Firefox 1.5 and above with screen resolution of 1024 X 768.