exit for inside try catch results in unexpected behavior
I'm finding that exit for, inside of try catch give a strange stack trace. The exit for is legit, in this code, and the code behaves as expected, if the try catch block is removed
George Cook https://georgejecook.github.io/ https://linkedin.com/in/georgejecook/ Roku developers slack group (https://join.slack.com/t/rokudevelopers/shared_invite/zt-4vw7rg6v-NH46oY7hTktpRIBM_zGvwA) : georgejecook
Contact me on roku developer slack group, or via pm to discuss consultancy/work opportunities/rooibos unit testing framework
Re: exit for inside try catch results in unexpected behavior
Confirming - issue exists when EXIT FOR is used in FOR EACH loop nested in a TRY/CATCH statement. Other loops (numeric FOR, WHILE) are not affected.
Brightscript Debugger> try: for each i in : ? i: exit for: end for: catch e: ? "except", e: end try
UNEXPECTED INTERNAL. (runtime error &hfe) in $LIVECOMPILE(703)
Behavior: "Unexpected internal" error at runtime, when EXIT FOR is to be executed.
Notice this only happens for syntactical nesting of FOR EACH inside TRY/CATCH within the same function, it won't happen if TRY/CATCH is further down in the call stack, e.g.
Brightscript Debugger> proc = sub(): for each i in [1,2]: ? i: exit for: end for: divZero = 1/0: end sub
Brightscript Debugger> try: proc(): catch e: ? "except", e: end try
except <Component: roAssociativeArray> =
backtrace: <Component: roArray>
message: "Divide by Zero."
Workaround: avoid nesting TRY > FOR EACH > EXIT FOR within the code of a single function. Use WHILE > EXIT WHILE or FOR-TO > EXIT FOR or boolean flag where feasible. Or separate TRY/CATCH from FOR EACH > EXIT FOR with a nested call.