[Gambas-user] "If Error" is ambiguous

T Lee Davidson t.lee.davidson at gmail.com
Mon Sep 9 16:14:41 CEST 2019


On 9/9/19 6:46 AM, Christof Thalhofer wrote:
> Hello,
> 
> I think I found a bug in Gambas, but I am not sure:
> 
> Normally "If Error" is used to detect if an error happed (and afterwards
> the programmer usually clears the error):
> 
> --------------------------------------------------------
> Try blah()
> If Error then
>      DoSth()
>      Error.Clear
> EndIf
> --------------------------------------------------------
> 
> But after Error.Clear Error continues to report True although the error
> was cleared:
> 
> --------------------------------------------------------
> Public Sub Main()
> 
>      Dim x As Float
> 
>      Try x = 2 / 0
> 
>      If Error Then
>          Error.Clear
>      Endif
> 
>      If Error Then
>          Print "Error still true"
>      Endif
> 
> End
> --------------------------------------------------------
> 
> What do you think about that?
> 
> Alles Gute
> 
> Christof Thalhofer
> 

According to the Wiki [0], Error.Clear "Resets the error code to zero and the error message to NULL."

And [1], "The error flag is reset to FALSE when:

The RETURN instruction is executed.

A TRY instruction has been executed without any error."

It does seem logical that Error.Clear should also reset the error flag.

[0] http://gambaswiki.org/wiki/comp/gb/error/clear
[1] http://gambaswiki.org/wiki/lang/error


___
Lee


More information about the User mailing list