L
Leslie Viljoen
[Note: parts of this message were removed to make it a legal post.]
Hi everyone
I want to make a custom exception like so:
class BillRowError < StandardError
def initialize(field, index)
@field = field
@index = index
end
end
I'll call this like so:
raise(BillRowError.newroamingcalls, @index), "Roaming Calls field
missing") if n.length == 0
But now I'd like to be able to modify the string that Ruby prints when the
exception is not rescue'd. I thought I could add this method to the
BillRowError class:
def message
@message + " field: #{@field}, row: #{@index}"
end
That almost works but I get a "instance variable @message not initialized"
warning, which means Ruby is not setting @message in my object like I
expected. Making my own message= method doesn't help.
Can an exception object access and modify the message that gets passed in
the "raise"?
Hi everyone
I want to make a custom exception like so:
class BillRowError < StandardError
def initialize(field, index)
@field = field
@index = index
end
end
I'll call this like so:
raise(BillRowError.newroamingcalls, @index), "Roaming Calls field
missing") if n.length == 0
But now I'd like to be able to modify the string that Ruby prints when the
exception is not rescue'd. I thought I could add this method to the
BillRowError class:
def message
@message + " field: #{@field}, row: #{@index}"
end
That almost works but I get a "instance variable @message not initialized"
warning, which means Ruby is not setting @message in my object like I
expected. Making my own message= method doesn't help.
Can an exception object access and modify the message that gets passed in
the "raise"?