• Question on Stack Tracing

    By David Leedy 2 decades ago

    I guess I'm having some trouble with using stack traceing..



    My impression is that any error trapping in a function in a scriptlibrary should send the error back to the calling code. I'm trying to do this by using the AddToStackTrace function rather then LogError() do my handler in a function might look like this:



    errorhandler:

     call addtostacktrace()<br/>
    



    End function





    My thinking is that the error should then be passed to the calling code of the original button or agent but that's not what's happening.



    If I use the handle from as shown above then the error gets logged in open log but the calling function is reporting a No RESUME error.



    If I change the handle in the function to this:



    getout:

    exit function



    errorhandler:

    call addtostacktrace()

    resume getout



    Exit Function



    Then the error does not get logged to open log and the calling code does not report a problem.



    I would like the calling code to know about the original error in the function. Then I'll deal with it in the calling code. So if I pass an Error # 1001 the calling code get's that number and not Error# 19 - No Resume. Then I could do a select case to deal with the error.



    It would seem that conceptually I'm doing something wrong. Any advice would be appreciated.

    • You need to throw the error

      By Peter Herrmann 2 decades ago

      You've probably solved this but this is how I do it. (I think the doc needs to be more specific about this.)



      When you do the following:



      handleError:

         Call AddToStackTrace()<br/>
      

      End Function



      the AddToStackTrace function is adding the name of current function to the info but is handling the error. You need to throw the error yourself. Like this:



      handleError:

         Call AddToStackTrace()<br/>
         Error Err, Error$                     ' throw the error <br/>
      

      End Function



      This works for me and gives me the results I expect.

      • Documentation is correct

        By John Smart 2 decades ago

        The documentation does not specify a Resume statement. Not having a Resume statement throws a "No Resume" error to the calling procedure.



        So, technically, the error thrown to the main function is the wrong error, but in reality it doesn't matter since the correct error has been stacked.



        By the way, LogError() is a string function that returns the error string, so your main error sub can be something like

        Messagebox LogError(), 48, "Error"