• No Logging When I use LotusScript Execute

    By Jens Winkelmann 2 decades ago

    I have a simple ScriptLibrary.

    The subroutine TestSub throws an error because of division by zero.



    ——————————————————————

    'BugScriptLibrary:



    Option Declare

    Option Compare Nocase, Nopitch

    Use "OpenLogFunctions"



    Sub Initialize

    <br/>
    

    End Sub





    Public Sub TestSub

    <br/>
    On Error Goto logerror<br/>
    <br/>
    Dim x As Variant, y As Integer<br/>
    x  = 1/  y<br/>
    <br/>
    Exit Sub<br/>
    

    logerror: Call LogError

    End<br/>
    <br/>
    

    End Sub



    ——————————————————————



    Then I have 2 agents which use the ScriptLibrary.



    Agent 1 uses the ScriptLibrary and calls the subroutine TestSub.

    The error will be catched by OpenLog. That is what I expect:



    ——————————————————————

    'AgentBug1:



    Option Declare

    Option Compare Nocase, Nopitch

    Use "BugScriptLibrary"



    Sub Initialize

    <br/>
    Call TestSub<br/>
    <br/>
    

    End Sub

    ——————————————————————



    Agent 2 does the same call but makes this via execute.

    This time the error will not be catched by OpenLog.



    ——————————————————————

    'AgentBug2:



    Option Declare

    Option Compare Nocase, Nopitch



    Sub Initialize

    <br/>
    Execute( |Use &quot;BugScriptLibrary&quot; : Call TestSub| )<br/>
    <br/>
    

    End Sub



    ——————————————————————



    The reason for this is that the OpenLogFunctions library is initialized by the Initialize subroutine in the same library.

    This works fine for the first agent.

    But when you use Exexute, Notes calls in step 1 the LogError subroutine and afterwards in step 2 the Initialize subroutine.

    So the Initialize subroutine will be called to late.



    For that reason I never use the Initialize subroutine.





    Workaround:



    Do the following enhancements:



    Private gHasBeenInitialized As Boolean





    Function LogError () As String

    <br/>
    '// Initialize<br/>
    If Not gHasBeenInitialized Then Call Initialize<br/>
    <br/>
    '** logs whatever error happens to be on the stack (if any)<br/>
    On Error Goto processError<br/>
    <br/>
    Call InitGlobalLogItem()<br/>
    


    ...<br/>
    



    Sub Initialize

    '** MODIFY THESE FOR YOUR OWN ENVIRONMENT<br/>
    <br/>
    gHasBeenInitialized = True<br/>
    <br/>
    '** this should be the name and path of the database that<br/>
    '** you're logging everything to -- you need to explicitly name<br/>
    '** it because it probably won't be the database that you're