Alpha Video Training
Results 1 to 13 of 13

Thread: goto "0"; resume "0"

  1. #1
    VAR
    Real Name
    Martin W. Cole
    Join Date
    Apr 2000
    Location
    Terrell, Texas (near Dallas)
    Posts
    5,957

    Default goto "0"; resume "0"

    am trying to understand these commands - I don't understand why the following script has two 'goto o' commands

    tries=0
    on error goto no_file
    '---we now have an active error trap
    fp=file.open(“a:custtemp.txt”)
    on error goto 0
    '---Dr. Wayne says this turns off the error trap
    '---I can't grasp why you would want to turn off the error trap
    text=fp.read_line()
    end
    no_file:
    on error goto 0 'does this also turn off the no_file error trap?
    tries=tries+1
    ui_msg_box(“Disk or file error”,”Place a diskette with custtemp.txt in drive A:”)
    if tries

  2. #2
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default RE: goto

    Martin, I've assumed that the command statement ON ERROR GOTO imposes a certain amount of overhead on the script. Presumably Alpha Five stops after each line to and checks to see if an error occurred, then executes the next line, stops and checks what happened, then executes the next line, stops and checks what happened... and so on. The implication of this is that the performance of the script will slow down as long as the error trap is active.

    So, in my own work here, I turn the trap off as soon as it's no longer needed.

    Depending on what happens in the error trap module itself, I frequently will turn off further trapping there, too. In these cases my script will have two separate ON ERROR GOTO 0 statements, like the one you posted.

    My goal is to enable trapping when it's needed, but to also turn it off as soon as possible, when it's no longer needed.

  3. #3
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default RE: goto

    Hi Tom,

    I believe what you said is absolutely correct, and while speed is not always critical, sometimes it is.

    But let me add that those who use Action scripting (with or without Inline Xbasic commands) are trapping the errors as well. Alpha 5 puts a default error trapping (pretty lousy code from the point of returning any useful info) code in the action code. If the trapping is turned off, Alpha has some default error reporting that is better than the code embedded in the Action Scripting.

    This is why I always use Xbasic code instead of Action Scripting.

    The other reason is that if I want trapping on all the time (perhaps for testing), I use a generic error trapping routine that will display errors in a helpful way. It can log the errors to a log file or display them or place them in the trace window. This is helpful for me when I want users to report errors back to me.

    Regards,

    Ira J. Perlow
    Computer Systems Design & Associates
    csda@mediaone.net

  4. #4
    VAR
    Real Name
    Martin W. Cole
    Join Date
    Apr 2000
    Location
    Terrell, Texas (near Dallas)
    Posts
    5,957

    Default RE: goto

    I hadn't thought of the overhead aspect - good thinking.

    But I still don't understand what it does, exactly. In Dr. Wayne's new book, he says he always uses a pair of them to avoid being caught in an endless loop.

    If "goto 0" turns off the trap - then Alpha, logically, would treat it as if it had been commented out, and from that point forward stop at the "end", and not goto "nofile".

    on error goto nofile
    tries=0
    read the "A" drive statements
    on error goto 0
    'if it reads successfully, turn off "nofile"
    'and stop at the "end" statement
    end
    nofile:
    on error goto 0 '?? to provide for an error within the trap itself??
    if tries

  5. #5
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,311

    Default RE: goto

    Martin,

    perhaps the distinction is in the Resume statement.

    I do not as a matter of course 'resume' at the spot which caused the error. I noticed your use of 'resume next 0', but the ramifications of it did not sink in until just now. Your 'resume next 0' will take the program back to the point which failed, and attempt it again. In this case you probably don't want to turn off the error trap just as it's headed back to the original point that failed the first time. In your design a single ON ERROR GOTO 0 will suffice.

    In my designs, I set the trap. If an error isn't thrown, I release the trap. If an error is thrown I also release the trap, but then I send the flow of the program logic elsewhere. Often to a spot a line or two 'before' the line which failed. Sometimes to a different branch of the program altogether.

    Maybe this is what Dr. Wayne had in mind in the script you are modeling.

    -- tom

  6. #6
    VAR
    Real Name
    Martin W. Cole
    Join Date
    Apr 2000
    Location
    Terrell, Texas (near Dallas)
    Posts
    5,957

    Default RE: goto

    The script is just a little snippet he was using to show how to send data to drive A. I know its probably very simple - but I am having the dickens of a time trying to undestand the use of "goto 0" - but I know its important because I've seen it used a lot in scripts. To me, since he said "on error goto 0" in the error trap itself, it would logically not trap any more attempts to put a disk in drive A, and the system would be "frozen" the next time a user tried. But since this doesn't happen - I think there is some sort of equivocation on my part with the phrase "turns off the error trap"

    I have seen "resume 0" used a lot in networking scripts -
    like
    tries=0
    on error goto cantget
    f=file.open("filename",file_rw_exclusive)
    cantget:
    if tries

  7. #7
    "Certified" Alphaholic
    Real Name
    Finian Lennon
    Join Date
    Apr 2000
    Location
    Atlanta, GA
    Posts
    1,805

    Default RE: goto

    Martin:

    I think you're getting tied up in the idea that "On Error GoTo 0" turns off error trapping. It doesn't, it restores the script to a state where, if an error occurs, you should see a "standard" A5 error message.

    In Peter's example (and in most error trapping) his code is designed to catch one very specific error, namely the absence of a disk in the drive. This is the only error that one would anticipate in this situation and the code catches it if it occurs. If the error does not occur he restores the default trapping immediately. Otherwise a later error - say a missing index tab in a t.index_primary_put() statement - would return the error message about a missing disk in drive A which, in the circumstances, wouldn't help very much!

    So, I think it's a good practice to write error traps for problems you can anticipate and then return the trapping to A5 for those you can't. This way each "on error goto" routine is immediately followed with an on error goto 0.

    Finian

  8. #8
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default RE: goto

    That was a very helpful explanation, Finian.
    Thanks,
    Peter

  9. #9
    "Certified" Alphaholic
    Real Name
    William Hanigsberg
    Join Date
    Apr 2000
    Location
    Toronto, ON
    Posts
    4,018

    Default RE: goto

    Hi all,

    Dr. Wayne explains somewhere that there is another reason for the "on error goto 0" statement.

    If you have "on error goto error_Handler" in a script the error handler has to look like

    error_handler:
    on error goto 0
    etc.
    etc.

    because were there an error in the error handler itself the code would go into an endless loop.

    And the more useful (and complicated) your error handler is, the more realistic it is to fear this possibility.

    Bill

  10. #10
    VAR
    Real Name
    Martin W. Cole
    Join Date
    Apr 2000
    Location
    Terrell, Texas (near Dallas)
    Posts
    5,957

    Default RE: goto

    Thank's Finnian - now if I understand correctly, one might have more than one error handler in a script - one for one reason(errors1) and one for another reason(errors2) - and once you got past reason 1 you would say on error goto errors2

  11. #11
    "Certified" Alphaholic
    Real Name
    Finian Lennon
    Join Date
    Apr 2000
    Location
    Atlanta, GA
    Posts
    1,805

    Default RE: goto

    Yes, that's what I do anyway!

    Finian

  12. #12
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default RE: goto

    Another view point and a special warning:

    First, looking at the original question: "why 2 lines with 'ON ERROR goto 0'"? The first 'ON ERROR goto 0' line is read only if there is no error. If an error occurs, the the script jumps to the label line thus bypassing the first 'ON ERROR goto 0' line and the second 'ON ERROR goto 0' is placed immediately after that line in order to reset the error trapping to use the A5 system traps.

    WARNING:
    Be very careful about using RESUME 0, RESUME NEXT, or RESUME label. I've found that the RESUME command often takes me to the line after the one I expect so I need to modify the script to handle this. I do this by adding a non-functional command line immediately after the label. (A blank line won't do it.)

    EXAMPLE:
    ON ERROR goto ErrorHandler
    tp = table.open( "tablename" )
    ON ERROR goto 0
    .
    .
    "add'l command lines>
    .
    .
    Continue_script:
    1=1 '--- THIS DOESN'T DO ANYTHING BUT TAKES UP ONE LINE.
    .
    .
    "rest of script>
    .
    .
    ErrorHandler:
    "script>
    "script>
    RESUME Continue_script

  13. #13
    VAR
    Real Name
    Martin W. Cole
    Join Date
    Apr 2000
    Location
    Terrell, Texas (near Dallas)
    Posts
    5,957

    Default RE: goto

    thank's Cal
    that's one of the many little idiosynchonacies that can take hours and hours to figure out

Similar Threads

  1. Previous not "locked" to "Auto"
    By Richard Froncek in forum Alpha Five Version 5
    Replies: 2
    Last Post: 03-05-2003, 01:03 PM
  2. Convert "02" to "2002"
    By Tony Watts in forum Alpha Five Version 5
    Replies: 4
    Last Post: 01-03-2003, 06:08 AM
  3. New "AlphaSports" with Detailed "Ho
    By Selwyn Rabins in forum Alpha Five Version 5
    Replies: 8
    Last Post: 12-27-2002, 07:43 AM
  4. Problem with "file.temp_create("C:"
    By Nathan White in forum Alpha Five Version 4
    Replies: 5
    Last Post: 12-31-2000, 05:59 AM
  5. Turning calc fields "on" or "off&qu
    By Wanda Friesen in forum Alpha Five Version 4
    Replies: 6
    Last Post: 05-01-2000, 07:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •