APerricone / harbourCodeExtension

Antonino Perricone's extension for visual studio code about Harbour and xHarbour programming languages
32 stars 20 forks source link

Evaluating an Errorblock in an Error handler causes an error #77

Open alexstrickland opened 3 years ago

alexstrickland commented 3 years ago

In the program below if the debugging code is linked in then the current error handler is called recursively until it crashes.


procedure Main()

    local bOldErrorBlock
    local n

    setMode(24, 80)
    if hb_isFunction("__DebugItem")
        ? "Debugger linked in"
    endif

    bOldErrorBlock := ErrorBlock({ |e| HandleError(e, bOldErrorBlock, .t.) })
    begin sequence
        n++
    recover
        ? "Recovered"
    end sequence

    ErrorBlock({ |e| HandleError(e, bOldErrorBlock, .f.) })
    begin sequence
        n++
    recover
        ? "Recovered"
    end sequence
    ErrorBlock(bOldErrorBlock)

return

function HandleError(e, bOldErrorBlock, lCarryOn)

    ? "HandleError " + hb_ValToStr(lCarryOn)
    if lCarryOn
        break
    endif

return eval(bOldErrorBlock, e)    

I love your addin! Thanks, Alex.

alexstrickland commented 3 years ago

The line where it calls the "wrong" error handler is 1190 in your current version of dbg_lib.prg (downloaded today): eval(t_oDebugInfo['userErrorBlock'], e)

APerricone commented 2 years ago

unluckily the errorblock management is a little messy on Harbour, on this particular case you can try using the BEGIN SEQUENCE WITH {| oErr | HandleError( oErr ) } syntax