patrickokeeffe Posted September 10, 2021 Share Posted September 10, 2021 Does try...catch do something undocumented regarding continue? I've been debugging the sequence below and the whole sequence halts anytime it hits catch(), instead of continue'ing as I had expected. It doesn't ever reach the 3rd print statement (after the continue) but it does fail to continue the while loop. My alert window shows these two messages and the sequence gets ended. Quote Ignoring error: C1136 Timeout: read_200wx_nmea0183 Line 34 finished delaying... next while loop I'm using DF 18.1 bld 2347 on Windows 10 Enterprise, with 'Run as administrator' compatibility mode enabled. I'm not using ignore(..) because I plan to re-initialize comms if C1136 occurs. (the try-catch block is my attempt to resolve this issue that's cropping up again: serial data streams cut out after indeterminate length of time and require reinitialization through the configuration menu) Auto-start sequence named "read_200wx_nmea0183": private string msg private string msgid private string vals private v1 private v2 while (1) try msg = Device.AIRMAR_200WX.ReadUntil(CHR(10)) catch ()//"C1136") ? "Ignoring error: " + strLastError delay(0.5) ? "finished delaying... next while loop" continue ? "should never reach here, after continue" endcatch if (Compare(Left(msg,1),"$")) continue // skip partial message endif // WARNING message checksum will be discarded without use msgid = Mid(msg,1,5) // defer data parsing until matching header is found switch // // ... lots of code removed ... // endcase endwhile Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted September 13, 2021 Share Posted September 13, 2021 Possibly. Personally I typically reverse my logic, checking for valid, rather than invalid cases, so don't use continue much. In your case, I would consider putting the entire script inside the while inside a try/catch block rather than just the comms handling. Quote Link to comment Share on other sites More sharing options...
patrickokeeffe Posted September 14, 2021 Author Share Posted September 14, 2021 The help for while loops (section 5.14) says this about continue: Quote The continue statement causes the sequence to jump back to the while statement, reevaluate the condition and either start the loop over, or break out of it It works as expected inside an if block (the second instance which discards partial messages) but inside the catch block it behaves funny. When serial comms fail, my command window should be littered with these two messages but instead they print once each and the sequence ends. So far I just added debug statements to help determine where the loop ends when it catches an error. I think it does make sense though to relocate the try-catch so it contains the whole script. Quote Link to comment Share on other sites More sharing options...
patrickokeeffe Posted September 14, 2021 Author Share Posted September 14, 2021 So I rearranged my try-catch block to wrap the entire script: while (1) try msg = Device.AIRMAR_200WX.ReadUntil(CHR(10)) if (Compare(Left(msg,1),"$")) continue // skip partial message endif // WARNING message checksum will be discarded without use msgid = Mid(msg,1,5) // defer data parsing until matching header is found switch // // ... lots of code removed ... // endcase catch ("C1136") ? "Caught serial comm error: " + strLastError delay(5) Device.AIRMAR_200WX.Purge() Device.AIRMAR_200WX.InitComm() //continue endcatch catch () ? "Ignoring error: " + strLastError endcatch endwhile With the second continue statement enabled, the sequence halts but without it, the loop keeps running until the comm error is resolved. Something about the catch block turns the continue into a break instead. Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted September 15, 2021 Share Posted September 15, 2021 Sounds like a bug. I've noted it so it is looked at and fixed in a future release. I tested with this simple sequence and it looks like continue inside of a catch() doesn't just break out of the while, but ends the sequence: while(1) delay(0.1) try ? 'a' ? b catch() ? 'c' continue endcatch ? 'd' endwhile ? 'e' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.