Error Handling

1.17 Error Handling

Erl Property

Microsoft.VisualBasic.Information


Erl

 

Return Value

An Integer containing the line number

Description

Indicates the line number on which an error occurred.

Err.Clear Method

Microsoft.VisualBasic.ErrObject


Err.Clear(  )

 

Description

Explicitly resets all the properties of the Err object after an error has been handled.

Err.Description Property

Microsoft.VisualBasic.ErrObject


Err.Description = string  To set the property
string = Err.Description  To return the property value

 

string required; String

Any string expression

Description

A read/write property containing a short string describing a runtime error.

Err.GetException Method

Microsoft.VisualBasic.ErrObject


Err.GetException(  )

 

Return Value

A System.Exception object or an object inherited from it containing the current exception

Description

Returns the Exception object associated with the current error.

Err.HelpContext Property

Microsoft.VisualBasic.ErrObject


Err.HelpContext

 

Description

A read/write property that either sets or returns an Integer value containing the context ID of the appropriate topic within a Help file.

Err.HelpFile Property

Microsoft.VisualBasic.ErrObject


Err.HelpFile

 

Description

A read/write String property that contains the fully qualified path of a Windows Help file.

Err.LastDLLError Property

Microsoft.VisualBasic.ErrObject


Err.LastDLLError

 

Description

A read-only property containing a system error code representing a system error produced within a DLL called from a VB program.

Err.Number Property

Microsoft.VisualBasic.ErrObject


Err.Number

 

Description

A read/write property containing a numeric value that represents the error code for the last error generated.

Err.Raise Method

Microsoft.VisualBasic.ErrObject


Err.Raise(number, source, description, helpfile, helpcontext)

 

number required; Long integer

A numeric identifier of the particular error

source optional; String

The name of the object or application responsible for generating the error

description optional; String

A useful description of the error

helpfile optional; String

The fully qualified path of a Microsoft Windows Help file containing help or reference material about the error

helpcontext optional; Long

The context ID within helpfile

Description

Generates a runtime error.

Err.Source Property

Microsoft.VisualBasic.ErrObject


Err.Source

 

Description

A read/write string property containing the name of the application or the object that has generated the error.

ErrorToString Function

Microsoft.VisualBasic.Conversion


ErrorToString([errornumber])

 

errornumber optional; Long

A numeric error code

Return Value

A String containing an error message

Description

Returns the error message or error description corresponding to a particular error code.

IsError Function

Microsoft.VisualBasic.Information


IsError(expression)

 

expression required; Object

An object variable that may be an Exception object

Return Value

Boolean (True if expression is an Exception object, False otherwise)

Description

Indicates whether an object is an instance of the Exception class or one of its derived classes.

On Error Statement

 


 
On Error GoTo label|0|-1  Syntax 1.
On Error Resume Next  Syntax 2.

 

label Either label, 0 , or -1 is required

A valid label within the subroutine

Description

Enables or disables error handling within a procedure.

If you don't use an OnError statement or a Try...Catch block in your procedure, or if you have explicitly switched off error handling, the Visual Basic runtime engine will automatically handle the error. First, it will display a dialog box containing the standard text of the error message. Second, it will terminate the application. So any error that occurs in the procedure will produce a fatal runtime error.

Resume Statement

 


 
 
Resume [0]
Resume Next 
Resume label

 

Description

Used to continue program execution when an error-handling routine is complete.

Throw Statement

 


Throw exception

 

exception required; System Exception or a derived type

An Exception object representing the exception being thrown

Description

Throws an exception that can be handled using either structured exception handling (a Try . . . Catch block) or unstructured exception handling (the On Error statement).

Try...Catch...Finally Statement

 


 
Try
  tryStatements
[Catch1 [exception [As type]] [When expression]
  catchStatements1
[Exit Try]
 
Catch2 [exception [As type]] [When expression]
  catchStatements2
[Exit Try]
...
Catchn [exception [As type]] [When expression]
  catchStatementsn]
[Exit Try]
 
[Finally
  finallyStatements]
End Try

 

exception optional; System.Exception or a derived type

The exception to catch. If exception is omitted or if it is System.Exception, all exceptions will be caught. However, if exception is omitted, no information about the exception will be accessible within the Catch block.

type optional

The data type of the exception to be handled by the Catch block. Its value can be System.Exception or any derived type. If omitted, its value defaults to System.Exception, and all exceptions will be handled.

expression optional; Boolean

A logical expression that defines a condition under which the error is to be handled by the Catch block.

Description

Handles runtime errors using Structured Exception Handling.

The tryStatements, which are required, constitute the Try block and are the statements that VB monitors for errors.

The Catchblocks, of which there can be more than one, contain code that is executed in response to VB "catching" a particular type of error within the Try block. Thus, the Catch blocks consist of the error-handlers for the Try block.

The phrases exception[Astype] and [Whenexpression] are referred to as filters in the VB.NET documentation. In the former case, exception is either a variable of type Exception, which is the base class that "catches" all exceptions, or a variable of one of Exception's derived classes. The When filter is typically used with user-defined errors.

The ExitTry statement is used to break out of any portion of a Try...Catch...Finally block.

The optional finallyStatements code block is executed regardless of whether an error occurs (or is caught), unless an ExitTry statement is executed.

Multiple Catch statements can be used. However, only the first Catch statement to be true is executed. This means that multiple Catch statements should be ordered from most specific to most general, with a Catch block handling errors of type System.Exception occurring last.

 



VB. NET Language Pocket Reference
VB.NET Language Pocket Reference
ISBN: 0596004281
EAN: 2147483647
Year: 2002
Pages: 31

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net