T
Tim Hunter
What am I doing wrong here? This little test program is based on the
example on p. 97 in the Pickaxe:
class MyError < StandardError
def initialize(loc)
@extra = loc
end
def extra
@extra
end
end
def read_file(name)
raise MyError.new("line 1"), "Unable to read file: #{name}"
end
begin
read_file('foo.jpg')
rescue MyError => error
puts "error=#{error}"
puts "error.extra=#{error.extra}"
end
I expect the 2nd puts to print "line 1". However, the output is:
[tim:~]$ ruby test.rb
error=MyError
error.extra=Unable to read file: foo.jpg
This is Ruby 1.6.8.
example on p. 97 in the Pickaxe:
class MyError < StandardError
def initialize(loc)
@extra = loc
end
def extra
@extra
end
end
def read_file(name)
raise MyError.new("line 1"), "Unable to read file: #{name}"
end
begin
read_file('foo.jpg')
rescue MyError => error
puts "error=#{error}"
puts "error.extra=#{error.extra}"
end
I expect the 2nd puts to print "line 1". However, the output is:
[tim:~]$ ruby test.rb
error=MyError
error.extra=Unable to read file: foo.jpg
This is Ruby 1.6.8.