I wanted to do something similar. I wanted to pass an object to #new and have the message set based on some processing of the passed object. The following works.
class FooError < StandardError attr_accessor :message # this is critical! def initialize(stuff) @message = stuff.reverse endendbegin raise FooError.new("!dlroW olleH")rescue FooError => e puts e.message #=> Hello World!end
Note that if you don't declare attr_accessor :message
then it will not work. Addressing the OP's issue, you could also pass the message as an additional argument and store anything you like. The crucial part appears to be overriding #message.