2

I would expect the following loop to execute 5 times, going to the next iteration if an error occurs, but it stops after the first iteration.

What am I doing wrong ?

I can make it continue even if errors occur inside the loop by placing an extra do block inside the loop, but I'm curious why that is needed.

block-level on error undo, throw.
define variable cnt as integer no-undo.
    
loop:    
do while true on error undo, next:

    cnt = cnt + 1.
    display cnt.
    if cnt >= 5 then leave. 
    integer ("abc").

    catch e as Progress.Lang.Error :
         message "error in loop" cnt skip
         e:getmessage(1) skip
         view-as alert-box.   
         next loop.
    end catch.
    
end.    
Mike Fechner
  • 6,627
  • 15
  • 17
carl verbiest
  • 1,113
  • 1
  • 15
  • 30
  • 1
    I think there is some infinity loop protection detection going on. If you replace ``do while true`` with ``do cnt = 1 to 5`` then the loop does continue. – Stefan Drissen May 15 '23 at 08:41
  • @StefanDrissen infinite loop protection crossed my mind, but I thought it only started after a couple of iterations, will try to locate the docs on that – carl verbiest May 15 '23 at 08:43

1 Answers1

3

As commented by Stefan Drissen, the behaviour is caused by infinite loop protection.

see https://community.progress.com/s/article/What-is-Infinite-Loop-Protection for more details.

I found 2 ways to avoid the protection

trick infinteloop detection mechanisme

kind of dirty trick

block-level on error undo, throw.
define variable cnt as integer no-undo.
    
loop:    
repeat while true:

    if retry then /* trick infinite loop detection */.
    cnt = cnt + 1.
    display cnt.
    if cnt >= 5 then leave. 
    integer ("abc").

    catch e as Progress.Lang.Error :
         message "error in loop" cnt skip
         e:getmessage(1) skip
         view-as alert-box.   
         next loop.
    end catch.
    
end. 

Add extra block

this one looks cleaner to me.

block-level on error undo, throw.
define variable cnt as integer no-undo.
    
loop:    
repeat while true:
    do on error undo, next:

        cnt = cnt + 1.
        display cnt.
        if cnt >= 5 then leave. 
        integer ("abc").

        catch e as Progress.Lang.Error :
            message "error in loop" cnt skip
                e:getmessage(1) skip
                view-as alert-box.   
            next loop.
        end catch.    
    end.
end. /* loop */
carl verbiest
  • 1,113
  • 1
  • 15
  • 30