I have a custom exception class as:
module ABC
class XYZ < Exception
end
end
I try to call my exception class in some other class as ::
raise ABC::XYZ "My Msg" if something != onething
I get the below exception:
NoMethodError: undefined method `XYZ' for ABC:Module
You’re just missing a comma, the line should be:
raise ABC::XYZ, "My Msg" if something != onething
Currently it’s being parsed as a method call to XYZ
with "My Msg"
as the parameter, which gives the error since there is no XYZ
method.
You need to raise an instance of ABC::XYZ
As you have it, the Ruby interpreter assumes you are trying to execute a method.
raise ABC::XYZ.new("My Msg") if something != onething
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With