Ruby - Using passed exceptions


You can receive exceptions and use them.

This is achieved with a little extra syntax on the rescue block:

  puts 10 / 0 
rescue => e 
  puts e.class 

Rather than merely performing some code when an exception is raised, the exception object itself is assigned to the variable e.

Then you can use that variable.

This is useful if the exception class contains extra functionality or attributes that you want to access.

Related Topic