Requires: gfawinx.lg32
Converts the information from the Err object in a single string.
str = ErrStr([info])
str, info | : string expression |
ErrStr is used in a Try/Catch/EndCatch handler (or OnError GoTo) to collect the information from the Err object properties into a single string. There is also the optional info argument which prompts ErrStr to insert some information in front of the error information; in this way the returned string could specify the name of the procedure which trapped the error.
The returned string omits information not related to the exception so if Err.Exception, Err.HResult, and/or Err.LastDllError are zero, then these properties aren’t included in the returned string. This way ErrStr returns the relevant information only.
$Library "gfawinx"
Try
Open "xxx.yyy" for Input As # 1
Close # 1
Catch
Debug.Show
Debug ErrStr("Main: Open")
EndCatch
This displays the following text:
Err.Number = 15
Err.Description = File name
Err.Source = GFA-BASIC 32
Err.HResult = 0x2: The system cannot find the file specified.
ErrStr highlights an undocumented feature: many GFA-BASIC 32 commands that generate errors specify additional information through the HResult property. When the high-word of the HResult property is zero the low-word returns the value returned by the API function GetLastError. The ErrStr function includes the system error message for that value, in the example above: ‘The system cannot find the file specified’. Often a GFA-BASIC runtime error specifies additional information in .HResult, even if the source of the error isn’t a COM error.
To quickly insert the name of the current procedure for the info parameter press App+P.
{Created by Sjouke Hamstra; Last updated: 11/08/2019 by James Gaite}