[Gambas-user] using try when access devices shadow the errors
T Lee Davidson
t.lee.davidson at gmail.com
Thu Aug 2 16:32:50 CEST 2018
On 08/01/2018 04:32 PM, PICCORO McKAY Lenz wrote:
> 2) also we also can raised the error using error.propagate but that are not so reflected in the wiki, and in the wiki there's no
> point about shadowing of errors if a try-catch are used
There is no such thing as a "try-catch" in Gambas. CATCH is *not* used with TRY.
Tobi gave a good example:
On 08/01/2018 03:10 PM, Tobias Boege wrote:
> Something more advanced: you can catch and rethrow errors in Gambas
> using Error.Propagate():
>
> Dim iTries As Integer = 5
>
> Do
> Try SComm.Open()
> Dec iTries
> While Error and iTries > 0
> If Error Then Error.Propagate()
>
> This will try to connect five times (without changing any parameter) and
> after the fifth failure, it will just take the error produced by the
> Open() method and forward it.
>
> This is a bit of a silly example for a serial port, but the idea is that
> you can catch an error using Try, then you attempt to recover from the
> error in a way that fits your problem, and if that also doesn't succeed,
> you propagate the error to your caller.
Your response was, "like it! but without usage of catch? ? ?"
Yes! CATCH is *not* used with TRY. TRY does not open an exception handling block as with other languages (eg. Python's
"try-except"). It is a statement that affects the behavior of only the *line* which it begins.
When using TRY, you test for an error condition with the ERROR keyword. If you do not, then the error is not revealed, and the
program would continue merrily along under a potentially false assumption. If you want to use CATCH, then do not use TRY.
___
Lee
More information about the User
mailing list