[Gambas-user] Catch Not Catching or is bypassed with the Finally...

Benoît Minisini g4mba5 at gmail.com
Wed Jun 26 22:12:16 CEST 2019


Le 26/06/2019 à 19:16, KKing a écrit :
> Is this correct behaviour while stepping through code in IDE?
> 
> In example below if an EOF is encountered on the Read, it jumps from the 
> read to the Finally statement and processes as if no error, though I 
> realised issue because the iResponse is -1.
> Shouldn't it jump to the Catch and depending on code then execute the 
> Finally just before leaving?
> 
> If I comment out the Finally, it does jump to the Catch and gives the 
> expected error details.
> 
> <<
> Sub ReadFile(hfile as File) as integer
> 
>      Dim iResponse
>      iResponse = -1
> 
>      Seek #hfile, 30
>      Read #hfile, someContent, 80
>      iResponse = 0
> 
> Finally
>      Try hfile.Close
>      hfile = null
>      return iResponse
> 
> Catch
>      Print Error.Code
>      stop
> 
> End
>  >>
> 
> K.
> 

It is. The code of FINALLY is always executed before the CATCH. It is 
intended to clean up things before propagating or displaying the error.

The current problem is that the Error object is global, and so can be 
overrident during the Finally part. I will try to make it transparently 
local to the function, but I'm not sure that it is possible yet.

Regards,

-- 
Benoît Minisini


More information about the User mailing list