[Gambas-user] "If Error" is ambiguous

Christof Thalhofer chrisml at deganius.de
Mon Sep 9 23:01:33 CEST 2019


Am 09.09.19 um 22:32 schrieb Benoît Minisini:

> The error flag is set once the TRY instruction has been executed.
> 
> The error exception management code does not care with that flag, this 
> is why Error.Clear() does not clear it. Actually nothing clears that 
> flag, except a new TRY instruction.
> 
> I don't think it's a problem if Error.Clear() would clear the flag.
> 
> Anyway, the 'If Error Then...' was intended to  be used just after a TRY 
> instruction and only in that occasion.
> 
> Maybe the compiler should raise a warning if we are not in that case, if 
> possible.

I am playing around with my unittests and there are occasions where the
same code first does a "Try ... If Error Then ... Error.Clear" and later
on the program has to detect if an error happened independently from that.

Here I stumbled over the behaviour of Gambas. For me I could fix it by
checking for Error.Code <> 0 but it was not intuitive. I rubbed my eyes
and had to get some sleep before I understood the problem.

I think it would be better to clear the flag with Error.Clear and I also
think it would not break older code.

Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190909/8f9ade8e/attachment.sig>


More information about the User mailing list