Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using catch-all in for-loops with "return" can lead to surprises #141

Open
sjmackenzie opened this issue Apr 29, 2011 · 1 comment
Open
Milestone

Comments

@sjmackenzie
Copy link
Member

It is possible to catch the exceptions that are used by the implementation of the (experimental?) "return"
feature of the for-loop. If this is done unintentionally, it can lead to hard-to-find bugs.

Example:

declare

fun {DivideBy X}
   42 div X
end

fun {Loop Fun}
   for I in [0 1 2 3] default:thisShouldNeverBeReturned return:R do
      try
         {R {Fun I}}
      catch E then
         skip
      end
   end
end

in
{Show {Loop DivideBy}}

The expected result is: 42
The actual result is: thisShouldNeverBeReturned

Possible strategy for fix: Let the for-loop implementation use a special kind of exception that can never be catched
by user code? (No idea whether this can be implemented, though.).

@doublec
Copy link
Member

doublec commented May 9, 2011

The same problem exists with 'break' and 'continue' - these are mentioned in the documentation though whereas the issue with 'return' is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants