Skip to content

Instantly share code, notes, and snippets.

@webuilder240
Created June 20, 2019 15:15
Show Gist options
  • Save webuilder240/2824ee1d0135678a84d0297ec3e9f36a to your computer and use it in GitHub Desktop.
Save webuilder240/2824ee1d0135678a84d0297ec3e9f36a to your computer and use it in GitHub Desktop.
例外の階層構造
module Nick
class NickError < StandardError; end
class NoCustomerError < NickError; end
class NoCardError < NickError; end
class NoMoneyError < NickError; end
end
begin
raise Nick::NoMoneyError.new()
rescue Nick::NickError => e
puts "#{e.class}はここにやってくる"
rescue => e
puts "ここにはこない"
end
begin
raise Nick::NickError.new()
rescue Nick::NoCardError,
Nick::NoCustomerError => e
puts "ここにはこない"
rescue => e
puts "#{e.class}はここにやってくる"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment