Announcement

Collapse
No announcement yet.

RESUME Questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    RESUME Questions

    I have a couple of questions in regard to error handling.

    Q1 - The manual notes that you must terminate a error trap with a RESUME statement. Could you not just fall out of the sub/func as well or do you have to RESUME?

    Q2 - I see noted a RESUME label and a RESUME Next but not a RESUME. How would you try the offending line again?

    Q3 - If you want to cancel error trap for a couple lines of code you can use the RESUME NEXT. How do you start the error trap again for that sub/func?

    Code:
    Private Sub MySub()
      On Error Goto ErrorRoutine
      (some code....................)
    
      'stop error trap
      On Error Resume Next 
      (some code....................)
      On Error Goto 0
    
      (some code....................)
    
    ErrorRoutine:
      (some code....................)
    
    End Sub
    In the code above after the On Error Goto 0 would the On Error Goto ErrorRoutine be in effect?

    Thanks.

    #2
    All error traps must have a RESUME <linelabel>.

    ie,
    Code:
    FUNCTION MyFunc....
       ON ERROR GOTO MyFuncTrap
       ....
        
    MyFuncResumePoint:
       EXIT FUNCTION
     
    MyFuncTrap:
       ' handle error here
       RESUME MyFuncResumePoint
    END FUNCTION
    You can't resume the same line again - it is not possible - the compiler would need to add significant additional code to your app for every single line of code.

    Instead, you simply need to write your code to either handle errors as they occur (no trap or use RESUME NEXT, and check ERR as necessary) or write your error trap to branch back above the line you wish to resume again - you can have several RESUME <Linelabel> depending on the state of ERR, etc. This way permits you to keep the code size down and performance up, whilst constructing as much or a little error testing as you need yourself.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


      #3
      Lance, Thank you!!!

      Could you be a little more specific about Q3.

      ------------------

      Comment


        #4
        ON ERROR GOTO ErrTrap
        ...
        ON ERROR GOTO 0
        ...
        ON ERROR RESUME NEXT
        ...
        ON ERROR GOTO ErrTrap

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎