Sha256: d40bd64ccdfb78e9e9af637db6c74dfd7989f3e88e207fc08f31a5915198f15f

Contents?: true

Size: 456 Bytes

Versions: 6

Compression:

Stored size: 456 Bytes

Contents

class Exception

  # Supress errors while executing a block, with execptions.
  #
  #  CREDIT: Trans
  #  CREDIT: David Heinemeier Hansson

  def self.suppress(*exception_classes)
    exception_classes.each do |e|
      unless e < self
        raise ArgumentError, "exception #{e} not a subclass of #{self}"
      end
    end
    begin yield
    rescue Exception => e
      raise unless exception_classes.any? { |cls| e.kind_of?(cls) }
    end
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
facets-2.4.1 lib/facets/exception/suppress.rb
facets-2.4.4 lib/core/facets/exception/suppress.rb
facets-2.4.2 lib/core/facets/exception/suppress.rb
facets-2.4.3 lib/core/facets/exception/suppress.rb
facets-2.4.5 lib/core/facets/exception/suppress.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/exception/suppress.rb