Contains information about runtime errors. Accepts the Raise and Clear methods for generating and clearing run-time errors.
Err [.{property | method}]
The Err object is an intrinsic object with global scope, there is no need to create an instance of it in your code. The properties of the Err object are set by the generator of an error - GFA-BASIC 32, an Automation object, or the programmer.
The default property of the Err object is Number. Err contains an integer.
See Err$ for a list of errors and exception codes.
When a run-time error occurs, the properties of the Err object are filled with information that uniquely identifies the error and information that can be used to handle it. To generate a run-time error in your code, use the Raise method.
Number | Description | HelpContext | HelpFile | Source | LastDllError | HResult | Exception
The following code shows how to handle error # 46 ("Error with object"), which is often set after an error with an automation object.
ObjectErr()
Sub ObjectErr()
Dim ObjectRef As Object, Msg$
' Try to start non existent object
Try
Set ObjectRef = GetObject("MyWord.Basic")
Catch
If Err.Number = 46
Msg = "There was an error attempting to open the Automation object!" + _
#10 "Description: " + Err.Description + _
#10 "HResult: " + Hex(Err.HResult) + _
#10 "Source: " + Err.Source
MsgBox Msg
End If
EndCatch
End Sub
The next example shows two different ways how to 'throw' custom or user-defined errors:
Try
CustomError1()
Catch
~MsgBox("Error" & Err & ": " & Err$, 0, Err.Source)
EndCatch
Try
CustomError2()
Catch
~MsgBox("Error" & Err.Number & ": " & Err.Description, 0, Err.Source)
EndCatch
Proc CustomError1()
Err.Number = 153
Err.Source = "Custom Error1"
Err.Description = "Random Error"
Err.Throw
EndProcedure
Proc CustomError2()
Err.Raise 153, "Custom Error2", "User Defined Error"
EndProcedure
The nature of the system Err object/value is one of the big changes in GFA-BASIC 32. In previous version of GFA-BASIC, the Err value was a global system variable of type integer. In GFA-BASIC 32, it is a COM object with a default Number property (a long integer). As a result, the Err statement behaves exactly as in GFA-BASIC 16, because it is a shortcut for Err.Number.
The GFA-BASIC 32 error numbers are in the range from 0-152. See Err$ for a list of errors and exception codes and strings.
{Created by Sjouke Hamstra; Last updated: 11/01/2017 by James Gaite}