I am new to Ruby, so I am having trouble understanding this strange exception problem that I am experiencing. I use the ruby-aaws gem to access Amazon ECS: http://www.caliban.org/ruby/ruby-aws/ . This defines the Amazon :: AWS class: Error:
module Amazon
module AWS
module Error
class AWSError
attr_reader :exception
def initialize(xml)
err_class = xml.elements['Code'].text.sub( /^AWS.*\./, '' )
err_msg = xml.elements['Message'].text
unless Amazon::AWS::Error.const_defined?( err_class )
Amazon::AWS::Error.const_set( err_class,
Class.new( StandardError ) )
end
ex_class = Amazon::AWS::Error.const_get( err_class )
@exception = ex_class.new( err_msg )
end
end
end
end
end
This means that if you get an error code, for example AWS.InvalidParameterValue, it will lead (in its exception variable) to a new class Amazon::AWS::Error::InvalidParameterValue, which is a subclass StandardError.
Now that is getting weird. I have a code that looks like this:
begin
do_aws_stuff
rescue Amazon::AWS::Error => error
puts "Got an AWS error"
end
, do_aws_stuff NameError, . , Amazon:: AWS:: Error - , , ? , :
irb(main):007:0> NameError.new.kind_of?(Amazon::AWS::Error)
=> true
true, , :
irb(main):009:0> NameError.new.kind_of?(Amazon::AWS)
=> false
, AWS ? - :
begin
do_aws_stuff
rescue => error
if error.class.to_s =~ /^Amazon::AWS::Error/
puts "Got an AWS error"
else
raise error
end
end
. AWSError: :
error = Amazon::AWS::Error::AWSError.new( xml )
raise error.exception
, , rescue from, , StandardError.
, :
NameError, Ruby , kind_of?(Amazon::AWS::Error), ?
: include Amazon::AWS::Error , , Java ++. , , , Amazon::AWS::Error ( ) Kernel, . , - kind_of?(Amazon::AWS::Error).
Amazon::AWS::Error ?