harbourCodeExtension icon indicating copy to clipboard operation
harbourCodeExtension copied to clipboard

Evaluating an Errorblock in an Error handler causes an error

Open alexstrickland opened this issue 4 years ago • 2 comments

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 avatar May 28 '21 14:05 alexstrickland

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)

alexstrickland avatar May 29 '21 12:05 alexstrickland

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

APerricone avatar Oct 25 '22 12:10 APerricone