[Gambas-user] Finally/Catch and Return: How is that meant to be used?
Martin Fischer
martin.fischer6 at web.de
Thu Sep 14 17:04:16 CEST 2023
>
> The only way to deal with that problem I see is the following:
>
> -----------------------
> Public Function getComplicatedId() As Integer
> Dim result As Integer
> Dim bReturn As Boolean
>
> ' do some very complicated stuff
> ' resources are allocated on the way. E.g. heap Alloc
>
> bReturn = True
>
> Finally
> ' clean up resources here
> if bReturn Then Return result
>
> Catch
> ' do some logging here
> Error.Raise("Can't handle this!")
> End
> -----------------------
>
> The interpreter misses a flag local to the function that allows to tell
> that Finally was reached without raising an error.
>
> Regards,
>
Benoit,
yes, that does the job.
But, well, it feels a bit ugly...
I mean: it's hard to define the proper semantics of Finally with this
'complications'.
Anyway, thank you for the hint.
Maybe, in a release 4 or so, we will get a
'do-what-I-expect-you-to-do"-Finally??
Regards
Martin
More information about the User
mailing list