Forum Discussion
3 Replies
- RokuJonathanDCommunity Moderator
Hey George,
What specific use case for TRY/CATCH are you working on...please advise so I can see how we can best help you.
Thanks,
Jonathan
- NB_Roku Guru
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.
Minimalist repro:
Brightscript Debugger> try: for each i in [1]: ? i: exit for: end for: catch e: ? "except", e: end try 1 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 1 except <Component: roAssociativeArray> = { backtrace: <Component: roArray> message: "Divide by Zero." number: 20 rethrown: false }
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.
Stay tuned for a fix.