Debugging nested loops

Hello everyone,

I am trying to debug a complex function with nested for-loops by using the following trick to get some cues about which variables are causing problems

for ...
        some variables being allocated ( var1,var2 etc ... )
             bug = func(var1,var2,...)
        catch err1
             quit = false
             while quit == false
                     println("debug mode : (quit=true to quit)")
                     catch err2


I would like to get access to var1,var2,etc … without tediously adding or removing println(vari) in the loop, but when a bug appears and get into the while loop (“debug mode”), I can’t retrieve the for loop variables :

debug mode : (quit=true to quit) # entered in debug mode
println(var1) # trying to get the value of var1
UndefVarError(:var1) #not defined ?
debug mode : (quit=true to quit)#

I understand that the for and while loop define local variables but I thought that with this trick I will get access to these local variables and easily understand which variables are causing problems. How can I retrieve the whole environnement of the for loop in the first catch section ?

In the future I would like to use this to rapidly troubleshoot some functions, so if someone could tell me what I am doing wrong I would be very grateful !

Thank you in advance !

1 Like