vendredi 3 novembre 2023

Why do I get NoMethodError: undefined method `rescue' for #

Ruby's Concurrent::Future was not catching the exceptions. So I copied the code from an article to add a rescue block. But now I got the error:

Caused by NoMethodError: undefined method `rescue' for #Concurrent::Future:0x0000000124764268

Here is the code:

executed_future = Concurrent::Future.execute do
            url = "#{endpoint}#{datum[:hierarchy_id]}#{valuation_date}"
            raise StandardError.new("Testing error!") # To test

            [...]
          end.rescue do | exception | # Adding this, will throw the error
            @exceptions << exception
            binding.pry # No activated
          end

What am I missing?

I expect to rescue exceptions in the Concurrent::Future block. Just like the article does.

Aucun commentaire:

Enregistrer un commentaire