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

Throwing an exception inside map doesn't trigger retries #10

Closed
harrigan opened this issue Sep 24, 2015 · 1 comment
Closed

Throwing an exception inside map doesn't trigger retries #10

harrigan opened this issue Sep 24, 2015 · 1 comment

Comments

@harrigan
Copy link

(try-try-again
  (fn []
    (map
      #(do
        (println "foobar:" %)
        (throw (Exception.)))
    (range 5))))

produces

foobar: 0
clojure.lang.Compiler$CompilerException: java.lang.Exception

with no retries. Should it? I'm likely missing something obvious here.

@joegallo
Copy link
Owner

Inside try-try-again, you're creating a lazy seq using map. No error is generated. You return that lazy-seq to the calling context of try-try-again, again with no error being generated.

Then, I'm assuming in your repl, you go to use or print the contents of your lazy seq, and finally the map is sortof actually evaluated, and you trigger the exception. But by now you're outside the context of try-try-again, and there's no opportunity for retries.

That is, you're being bitten by laziness. Use a doall to force the map to run inside try-try-again.

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

No branches or pull requests

2 participants