Rescue error with custom exception

I would like to rescue some code with a custom exception class. Here
some code:

class CustomError < StandardError
end

begin
‘foo’.bar(:baz)
rescue CustomError

THIS IS FINE

end

However, my class is not able to rescue the NoMethodError exception.

Is there a way to rescue this exception with a custom class such as
CustomError?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs