From: Brian Candler Date: 2010-04-07T00:24:39+09:00 Subject: Re: Custom Exceptions Judging by the C source, Exception uses hidden(*) instance variables "mesg" and "bt" for message and backtrace respectively. However, the accessor #message internally calls #to_s, which you can override. class BillRowError < StandardError def initialize(field, index) @field = field @index = index end alias :orig_to_s :to_s def to_s "#{orig_to_s} field: #{@field}, row: #{@index}" end end begin raise BillRowError.new(5, 7), "bar" rescue BillRowError => e p e p e.instance_variables p e.message p e.backtrace end Produces: # ["@index", "@field"] "bar field: 5, row: 7" ["ert.rb:14"] Admittedly this behaviour doesn't seem to be well documented, so may be fragile. Use at your own risk. HTH, Brian. (*) It uses instance variables whose names don't begin with '@' and so cannot be accessed by normal code -- Posted via http://www.ruby-forum.com/.