I would like to rescue some code with a custom class in Ruby 2.3 and 2.4. But unlike with the previous versions (such as 2.2 which was working great), I have some troubles. Here an example:
Given this class:
class CustomError < StandardError
end
This code is successfully rescued:
begin
'foo'.bar(:boom)
rescue
puts 'THIS IS FINE.'
end
# => printing "THIS IS FINE." on the screen
This one is also successfully rescued:
begin
'foo'.bar(:boom)
rescue StandardError
puts 'THIS IS FINE.'
end
# => printing "THIS IS FINE." on the screen
But not this one:
begin
'foo'.bar(:boom)
rescue CustomError
puts 'THIS IS FINE.'
end
This message is raised:
undefined method `bar' for "foo":String (NoMethodError)
I don't know why my custom exception class is not handled.