<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2018-08-01 15:10 GMT-04:00 Tobias Boege <span dir="ltr"><<a href="mailto:taboege@gmail.com" target="_blank">taboege@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Now this can be a bit confusing because the error keyword in Gambas means<br>
three things, even at the top level:<br>

  * It is the name of a class Error in the gb component, where more<br>
    information about the last error that occured is stored,<br></blockquote><div><a href="http://gambaswiki.org/wiki/comp/gb/error">http://gambaswiki.org/wiki/comp/gb/error</a> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  * It is a printing instruction like Print, but instead of standard output,<br>
    it prints to standard error,<br>
  * The last meaning is the one that is relevant to the code above:<br>
    it is True if and only if the last Try statement detected an error.<br></blockquote><div><a href="http://gambaswiki.org/wiki/lang/error">http://gambaswiki.org/wiki/lang/error</a> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
because the error keyword in Gambas means<br>
three things<br></blockquote><div>ok two thinks here! <br>first in the other mail my point was tha by example> "shadowed by the try.."<br></div><div>in the wiki there's no not4es about that, causing very hard waste of time<br></div><div>second the wiki must point that important difference about ERROR keyword<br></div><div><br>> interpreter sends you straight into the Catch block, which is executed<br>> and the "error flag" is cleared. Once you went through the Catch block,<br>this it's other important information that does are not in the wiki.. <br></div><div>and produce a waste of time when novice like me does not knowed!<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Now to your question: if you want to propagate an error, simply don't<br>
catch it, neither with Try nor Catch. Gambas will propagate an error<br></blockquote><div>if i made that, ide stop in that instruction! progams does not continue! <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
that happens in a function automatically to the calling function, and<br>
if that doesn't handle it, the error is forwarded to the next caller<br></blockquote><div>in the other mail i mention the usage of Error.propagate..<br></div><div>but so why try-catch does not handle it as many other languages?<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On the other hand, if you arrive at the outmost function on the call stack,<br>
and no function bothers handling the error, the interpreter will look for<br>
the Static Public Sub Application_Error [3] in the startup class of your<br>
project. This is a global "catch all" event handler that you can use to<br>
maybe save important work.<br></blockquote><div>umm it does not are so usefull for me, <br>due my programs must run also in debian wheeze and jessie gambas version<br></div><div>, wiki said that are only since 3.5<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Something more advanced: you can catch and rethrow errors in Gambas<br>
using Error.Propagate():<br>
<br>
  Dim iTries As Integer = 5<br>
<br>
  Do<br>
    Try SComm.Open()<br>
    Dec iTries<br>
  While Error and iTries > 0<br>
  If Error Then Error.Propagate()<br>
<br>
This will try to connect five times (without changing any parameter) and<br>
after the fifth failure, it will just take the error produced by the<br>
Open() method and forward it.<br></blockquote><div>like it! but without usage of catch? ? ?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

This is a bit of a silly example for a serial port, but the idea is that<br>
you can catch an error using Try, then you attempt to recover from the<br>
error in a way that fits your problem, and if that also doesn't succeed,<br>
you propagate the error to your caller.<br>
<br>
The Try method is good if you have a chance of recovering from the error<br>
inside the function itself. On the other hand, the Catch block [4] does<br>
not let you resume execution of your function: when an error happens, the<br>
interpreter sends you straight into the Catch block, which is executed<br>
and the "error flag" is cleared. Once you went through the Catch block,<br></blockquote><div>this it's other important information that does are not in the wiki<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
the function returns normally and the error is forgotten, not propagated,<br>
because it is assumed that you used the Catch block to handle it.<br>
The Catch block would be more useful in a function which expects its<br>
callees to fail sometimes and in that case abort the mission altogether,<br>
but without crashing the whole process.<br></blockquote><div>that's what i want!<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Notice that all I talked about involved the words "caller", "callee" and<br>
possibly "call stack". Error handling in Gambas (and probably everywhere<br>
else) goes along the dynamic scope. You can catch an error which happens<br>
in a function only if you are that function or if you called it (or called<br>
a function that called it, and so on). What you can *not* do is propagate<br>
an error from one class into another class you inherit from.<br></blockquote><div>WHAT? sound logical, but cannot propagate to the instance from? lest see that you explain now:<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
So, in the context of that other thread you mentioned, if you have two<br>
classes GenericPrinter and EpsonPrinter and you call<br>
<br>
  $hEpson.Write()<br>
<br>
then it will dispatch to the specific Write method of the EpsonPrinter object.<br>
If an error happens in there, you can *not* propagate and handle it inside<br>
the GenericPrinter.Write method. If you call<br>
<br>
  $hEpson.Open()<br>
<br>
(for which EpsonPrinter has no special version, so it dispatches to the<br>
generic Open method of GenericPrinter), and an error occurs there, then<br>
the code in the GenericPrinter will have to handle the error and even though<br>
you have an EpsonPrinter object there, the EpsonPrinter class is not in<br>
charge of handling the error, as you are executing a method defined in<br>
GenericPrinter.<br></blockquote><div>it's a new problem now, and in not have a property way to manage, <br>but this are more a topic for the context of that other thread<br><br></div><div>so then i limit this thread to the two problems:<br></div><div>1) we must manage using the error keyword usage, but taking care of the differences between clas error and keyword error, <br></div><div>in that, taking note as error.text are cleared if a catch block was used!<br><br></div><div>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<br><br>so the only suspected part are: "A <a href="http://gambaswiki.org/wiki/lang/try">TRY</a> instruction has been executed without any error." in the error keyword wiki at <a href="http://gambaswiki.org/wiki/lang/error">http://gambaswiki.org/wiki/lang/error</a> so novice users can be more confused rather well oriented<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Regards,<br>
Tobi<br>
<br>
[1] <a href="http://gambaswiki.org/wiki/comp/gb/error" rel="noreferrer" target="_blank">http://gambaswiki.org/wiki/<wbr>comp/gb/error</a><br>
[2] <a href="http://gambaswiki.org/wiki/lang/error" rel="noreferrer" target="_blank">http://gambaswiki.org/wiki/<wbr>lang/error</a><br>
[3] <a href="http://gambaswiki.org/wiki/comp/gb/application" rel="noreferrer" target="_blank">http://gambaswiki.org/wiki/<wbr>comp/gb/application</a><br>
[4] <a href="http://gambaswiki.org/wiki/lang/catch" rel="noreferrer" target="_blank">http://gambaswiki.org/wiki/<wbr>lang/catch</a><br>
[5] <a href="http://gambaswiki.org/wiki/lang/finally" rel="noreferrer" target="_blank">http://gambaswiki.org/wiki/<wbr>lang/finally</a><br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
-- <br>
"There's an old saying: Don't change anything... ever!" -- Mr. Monk<br>
<br>
----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" rel="noreferrer" target="_blank">https://www.hostsharing.net</a> ]----<br>
</font></span></blockquote></div><br></div></div>