Sha256: 57d7c33f6017d0b45347d0e3f2440a521fac12243fd98a5713273385eaab1e29

Contents?: true

Size: 451 Bytes

Versions: 10

Compression:

Stored size: 451 Bytes

Contents

class Exception

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

  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

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/exception/suppress.rb
facets-2.8.3 lib/core/facets/exception/suppress.rb
facets-2.8.2 lib/core/facets/exception/suppress.rb
facets-2.8.1 lib/core/facets/exception/suppress.rb
facets-2.8.0 lib/core/facets/exception/suppress.rb
facets-2.7.0 lib/core/facets/exception/suppress.rb
facets-2.6.0 lib/core/facets/exception/suppress.rb
facets-2.5.1 lib/core/facets/exception/suppress.rb
facets-2.5.0 lib/core/facets/exception/suppress.rb
facets-2.5.2 lib/core/facets/exception/suppress.rb