1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
class Class
alias old_new new
def new *a,&b
puts "{self.inspect}::new(#{a.inspect}, &#{b.inspect})"
r = old_new *a,&b
puts r.object_id
r
end
end
class E < Exception
def initialize *a
puts "{self.inspect}::initialize(#{a.inspect})"
end
def respond_to? name
puts "{self.inspect}::respond_to?(#{name})"
super
end
def exception *a
puts "{self.inspect}::exception(#{a.inspect})"
super
end
def backtrace
puts "{self.inspect}::backtrace"
['goo']
end
def set_backtrace value
puts "{self.inspect}::set_backtrace(#{value.inspect})"
value + ['hoo']
end
end
puts "--- raise(Exception, string, array) --------------"
begin
puts '> raise:'
raise E.new(1,2), "foo", ["x","y"]
rescue Exception => e
puts '> rescue:'
p e.object_id
p $@
end
puts "--- raise(Exception, array) --------------"
begin
puts '> raise:'
raise E.new(1,2), ["x","y"]
rescue Exception => e
puts '> rescue:'
p e.object_id
p $@
end
puts "--- raise(Exception, string) --------------"
begin
puts '> raise:'
raise E.new(1,2), "foo"
rescue Exception => e
puts '> rescue:'
p e.object_id
p $@
end
puts "--- raise(Exception) --------------"
begin
puts '> raise:'
raise E.new(1,2)
rescue Exception => e
puts '> rescue:'
p e.object_id
p $@
end
puts "--- raise(Class) --------------"
begin
puts '> raise:'
raise E
rescue Exception => e
puts '> rescue:'
p e.object_id
p $@
end
|