This line says save the code in the start-rescue block whenever it throws an exception of type Exception . It just turns out that Exception is a top-level exception that inherits all other exceptions (for example, a syntax error, a method error, etc.). Because of this, all exceptions will be saved. Then it saves this instance of the exception in the ex variable, in which you can look further (for example, backtracking, message, etc.).
I read this guide to Ruby exceptions .
An example is the following:
begin hey "hi" rescue Exception => ex puts ex.message end
However, if the code in the initial block does not give an error, it will not go down the salvation branch.
begin puts "hi" rescue Exception => ex puts "ERROR!" end #=> Prints "hi", and does not print ERROR!
source share