Skip to content

Instantly share code, notes, and snippets.

@aks
Created October 20, 2023 19:48
Show Gist options
  • Save aks/4a8809d45d5e5ad022ac55aa262cc12d to your computer and use it in GitHub Desktop.
Save aks/4a8809d45d5e5ad022ac55aa262cc12d to your computer and use it in GitHub Desktop.
Ruby script to show sub-class exceptions rescued before parent class exceptions
#!/usr/bin/env ruby
require 'awesome_print'
class Error < StandardError; end
class SpecificError < Error ; end
class Tester
def self.run
raise SpecificError
rescue Error, SpecificError => e
puts "caught: #{e.class}, #{e}"
end
end
Tester.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment