Module: Try

Defined in:
lib/try/try.rb,
lib/try/controls/error.rb

Defined Under Namespace

Modules: Controls

Class Method Summary collapse

Class Method Details

.call(*errors, error_probe: nil, &action) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/try/try.rb', line 2

def self.call(*errors, error_probe: nil, &action)
  errors = errors.flatten
  success = false

  begin
    action.call
    success = true
  rescue StandardError => e
    unless errors.empty?
      unless errors.include? e.class
        raise e
      end
    end
  end

  error_probe.call(e) unless error_probe.nil?

  return success
end