Number, Description, Exception Properties

Purpose

Return or set a numeric value and a short description of an error.

Syntax

Err.Number [= integer ]

Err.Description [= string ]

Err.Exception

Description

In case of a runtime error, GFA-BASIC 32 returns the value of the error in the Number property. The Description property returns a short description of the error. The numbers 0 to 141 are reserved for GFA-BASIC 32 errors. Other numbers can be used to generate user-defined errors. A list of error numbers and description are found here.

Number is the Err object's default property. Err is identical to Err.Number.

When Err = 46 an OLE object is the source of the error and you must inspect the HResult property for more details.

When Err is between 93 and 115, a system hardware or system software problem is responsible for the error. These events normally terminate program execution. Such events are called exceptions, and the mechanism that deals with exceptions is called structured exception handling. Normally, GFA-BASIC 32 reports these runtime errors with a message box and then terminates the program. By using structured exception handling you can handle both hardware and software exceptions. Therefore, your code will handle hardware and software exceptions identically. GFA-BASIC 32 supports structured exception handling with the Try/Catch/EndCatch statements. GFA-BASIC 32 translates the exception code into one of its own error numbers (93 to 115), but you can use the Exception property to retrieve a code that identifies the reason for the exception. For instance, an "Object is Nothing" error might be the result of an access violation, in which case Exception = $c0000005.

Inspecting and handling an error condition is only possible when the error is trapped. The preferred way in GFA-BASIC 32 is by using Try/Catch/EndCatch. However for compatibility reasons the VB structure On Error Goto can be used as well.

Example

Debug.Show

Local a

Try

Monitor ' a breakpoint

Catch

Debug Err.Number, Err$

Debug Hex(Err.Exception)

EndCatch

Try

a = (1 \ 0' integer division

Catch

Debug Err.Number, Err$

Debug Hex(Err.Exception)

EndCatch

Try

a = (1 / 0' floating point division

Catch

Debug Err.Number, Err$

Debug Hex(Err.Exception)

EndCatch

Try the all three error conditions by commenting the different lines. They are all the result of an exception.

See Also

Err Object, Err$, Try

{Created by Sjouke Hamstra; Last updated: 20/10/2014 by James Gaite}