module Serf::Util::ProtectedCall
Rescues exceptions raised when calling blocks.
Public Instance Methods
pcall(*args) { |*args| ... }
click to toggle source
A block wrapper to catch errors when executing a block. Instead of raising the error, the error is caught and returned in place of the block’s results.
ok, results = protected_call do 1 + 1 end => [true, 2] ok, results = protected_call do raise 'My Error' end => [false, RuntimeError]
@return boolean success and the block’s (or caught exception) results.
# File lib/serf/util/protected_call.rb, line 26 def pcall(*args) return yield(*args), nil rescue => e return nil, e end
Also aliased as: protected_call