Method: Kernel#suppress
- Defined in:
- lib/active_support/core_ext/kernel/reporting.rb
#suppress(*exception_classes) ⇒ Object
Blocks and ignores any exception passed as argument if raised within the block.
suppress(ZeroDivisionError) do
1/0
puts 'This code is NOT reached'
end
puts 'This code gets executed and nothing related to ZeroDivisionError was seen'
64 65 66 67 68 |
# File 'lib/active_support/core_ext/kernel/reporting.rb', line 64 def suppress(*exception_classes) yield rescue Exception => e raise unless exception_classes.any? { |cls| e.kind_of?(cls) } end |