module Bang::ExceptionExtension

Class-level extension for Exception class that adds ‘#raised?` and `#rescued?`.

Public Instance Methods

raised?() { || ... } click to toggle source

Yield a given block and return ‘true` if this exception specifically is raised, otherwise `false`.

@return [true,false] Whether exception is raised.

# File lib/bang.rb, line 319
def raised? #:yield:
  begin
    yield
    false
  rescue self => err
    self == err.class
  rescue Exception
    false
  end
end
rescued?() { || ... } click to toggle source

Yield a given block and return ‘true` if this exception, or a sub-class there-of is raised, otherwise `false`.

@return [true,false] Whether exception is rescued.

# File lib/bang.rb, line 336
def rescued? #:yield:
  begin
    yield
    false
  rescue self
    true
  rescue Exception
    false
  end
end