Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added should_reraise?

  • Loading branch information...
commit e9875e1ab035c60cc4a029b4d247600ed1597e4e 1 parent a2e8adc
@ms-ati authored
Showing with 16 additions and 0 deletions.
  1. +10 −0 lib/rumonade/error_handling.rb
  2. +6 −0 test/error_handling_test.rb
View
10 lib/rumonade/error_handling.rb
@@ -53,5 +53,15 @@ def and_then(func)
# x2 = catching(URI::InvalidURIError, NoMethodError).either { URI.parse(s) }
#
module ErrorHandling
+
+ # Should re-raise exceptions like +Interrupt+ and +NoMemoryError+ by default.
+ # @param [Exception] ex the exception to consider re-raising
+ # @return [Boolean] Returns +true+ if a subclass of +StandardError+, otherwise +false+.
+ def should_reraise?(ex)
+ case ex
+ when StandardError; false
+ else true
+ end
+ end
end
end
View
6 test/error_handling_test.rb
@@ -2,6 +2,7 @@
class ErrorHandlingTest < Test::Unit::TestCase
include Rumonade
+ include Rumonade::ErrorHandling
def test_partial_function_constructor_delegates_call_and_defined_at_to_given_procs
pf = PartialFunction.new(lambda { |x| x < 1000 }, lambda { |x| x * 10 })
@@ -31,4 +32,9 @@ def test_partial_function_and_then_returns_a_partial_function_with_func_called_o
.and_then(lambda { |x| x / 5 })
assert_equal 1800, pf.call(900)
end
+
+ def test_should_reraise_returns_true_if_not_subclass_of_standard_error
+ assert should_reraise?(NoMemoryError.new)
+ assert !should_reraise?(ZeroDivisionError.new)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.