Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
georgejecook
Streaming Star

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


image.png

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
0 Kudos
3 REPLIES 3
RokuJonathanD
Community Moderator
Community Moderator

Re: exit for inside try catch results in unexpected behavior

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

0 Kudos
RokuNB
Roku Guru

Re: exit for inside try catch results in unexpected behavior

George - this should not be happening, not in relation to `try/catch` anyhow. 

Please provide MWE to analyze, screenshot alone was no help. 

0 Kudos
RokuNB
Roku Guru

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. 

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. 

0 Kudos