Skip to content

Instantly share code, notes, and snippets.

@jeffmccune
Created April 16, 2012 16:41
Show Gist options
  • Save jeffmccune/2399867 to your computer and use it in GitHub Desktop.
Save jeffmccune/2399867 to your computer and use it in GitHub Desktop.
Sorting out Exceptions at Runtime
#! /usr/bin/env ruby
module Stomp
class Error < StandardError
end
end
module Jeff
def self.unknown_error
if Stomp.const_defined? "Error"
Stomp::Error
else
StandardError
end
end
end
def with_stomp
begin
yield
rescue Jeff.unknown_error => e
puts "Caught Connection Error: #{e}"
end
end
def raise_standard_error
raise StandardError, "Stomp 1.1"
end
def raise_stomp_error
raise Stomp::Error, "Stomp 1.2"
end
begin
with_stomp do
raise_stomp_error
end
rescue => e
puts "Uncaught Error: #{e.class}"
end
begin
with_stomp do
raise_standard_error
end
rescue => e
puts "Uncaught Error: #{e.class}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment