[Gambas-user] using try when access devices shadow the errors

PICCORO McKAY Lenz mckaygerhard at gmail.com
Wed Aug 1 22:32:56 CEST 2018


2018-08-01 15:10 GMT-04:00 Tobias Boege <taboege at gmail.com>:

> Now this can be a bit confusing because the error keyword in Gambas means
> three things, even at the top level:
>   * It is the name of a class Error in the gb component, where more
>     information about the last error that occured is stored,
>
http://gambaswiki.org/wiki/comp/gb/error

>   * It is a printing instruction like Print, but instead of standard
> output,
>     it prints to standard error,
>   * The last meaning is the one that is relevant to the code above:
>     it is True if and only if the last Try statement detected an error.
>
http://gambaswiki.org/wiki/lang/error

> because the error keyword in Gambas means
> three things
>
ok two thinks here!
first in the other mail my point was tha by example> "shadowed by the try.."
in the wiki there's no not4es about that, causing very hard waste of time
second the wiki must point that important difference about ERROR keyword

> interpreter sends you straight into the Catch block, which is executed
> and the "error flag" is cleared. Once you went through the Catch block,
this it's other important information that does are not in the wiki..
and produce a waste of time when novice like me does not knowed!


> Now to your question: if you want to propagate an error, simply don't
> catch it, neither with Try nor Catch. Gambas will propagate an error
>
if i made that, ide stop in that instruction! progams does not continue!

> that happens in a function automatically to the calling function, and
> if that doesn't handle it, the error is forwarded to the next caller
>
in the other mail i mention the usage of Error.propagate..
but so why try-catch does not handle it as many other languages?

On the other hand, if you arrive at the outmost function on the call stack,
> and no function bothers handling the error, the interpreter will look for
> the Static Public Sub Application_Error [3] in the startup class of your
> project. This is a global "catch all" event handler that you can use to
> maybe save important work.
>
umm it does not are so usefull for me,
due my programs must run also in debian wheeze and jessie gambas version
, wiki said that are only since 3.5


> 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.
>
like it! but without usage of catch? ? ?


> 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.
>
> The Try method is good if you have a chance of recovering from the error
> inside the function itself. On the other hand, the Catch block [4] does
> not let you resume execution of your function: when an error happens, the
> interpreter sends you straight into the Catch block, which is executed
> and the "error flag" is cleared. Once you went through the Catch block,
>
this it's other important information that does are not in the wiki


> the function returns normally and the error is forgotten, not propagated,
> because it is assumed that you used the Catch block to handle it.
> The Catch block would be more useful in a function which expects its
> callees to fail sometimes and in that case abort the mission altogether,
> but without crashing the whole process.
>
that's what i want!

Notice that all I talked about involved the words "caller", "callee" and
> possibly "call stack". Error handling in Gambas (and probably everywhere
> else) goes along the dynamic scope. You can catch an error which happens
> in a function only if you are that function or if you called it (or called
> a function that called it, and so on). What you can *not* do is propagate
> an error from one class into another class you inherit from.
>
WHAT? sound logical, but cannot propagate to the instance from? lest see
that you explain now:


>
> So, in the context of that other thread you mentioned, if you have two
> classes GenericPrinter and EpsonPrinter and you call
>
>   $hEpson.Write()
>
> then it will dispatch to the specific Write method of the EpsonPrinter
> object.
> If an error happens in there, you can *not* propagate and handle it inside
> the GenericPrinter.Write method. If you call
>
>   $hEpson.Open()
>
> (for which EpsonPrinter has no special version, so it dispatches to the
> generic Open method of GenericPrinter), and an error occurs there, then
> the code in the GenericPrinter will have to handle the error and even
> though
> you have an EpsonPrinter object there, the EpsonPrinter class is not in
> charge of handling the error, as you are executing a method defined in
> GenericPrinter.
>
it's a new problem now, and in not have a property way to manage,
but this are more a topic for the context of that other thread

so then i limit this thread to the two problems:
1) we must manage using the error keyword usage, but taking care of the
differences between clas error and keyword error,
in that, taking note as error.text are cleared if a catch block was used!

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

so the only suspected part are: "A TRY <http://gambaswiki.org/wiki/lang/try>
instruction has been executed without any error." in the error keyword wiki
at http://gambaswiki.org/wiki/lang/error so novice users can be more
confused rather well oriented



>
> Regards,
> Tobi
>
> [1] http://gambaswiki.org/wiki/comp/gb/error
> [2] http://gambaswiki.org/wiki/lang/error
> [3] http://gambaswiki.org/wiki/comp/gb/application
> [4] http://gambaswiki.org/wiki/lang/catch
> [5] http://gambaswiki.org/wiki/lang/finally
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180801/59ace6a0/attachment.html>


More information about the User mailing list