Module: ODDB::Failsafe

Included in:
App, OddbPrevalence
Defined in:
src/util/failsafe.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) failsafe(klass = StandardError, failval = :error, &block)



6
7
8
9
10
11
12
13
14
15
16
17
# File 'src/util/failsafe.rb', line 6

def failsafe(klass=StandardError, failval=:error, &block)
  begin
    "failsafe: #{klass}, calling block"
    block.call
  rescue klass => e
    puts "failsafe rescued #{e.class} < #{klass}"
    puts e.message
    puts e.backtrace
    $stdout.flush
    (failval == :error) ? e : failval
  end
end