Created
April 16, 2012 16:41
-
-
Save jeffmccune/2399867 to your computer and use it in GitHub Desktop.
Sorting out Exceptions at Runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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