Module: Dry::Monads::Try::Mixin::Constructors

Included in:
Dry::Monads::Try::Mixin
Defined in:
lib/dry/monads/try.rb

Instance Method Summary collapse

Instance Method Details

#Try(*exceptions, &f) ⇒ Try

A convenience wrapper for Dry::Monads::Try.run. If no exceptions are provided it falls back to StandardError. In general, relying on this behaviour is not recommended as it can lead to unnoticed bugs and it is always better to explicitly specify a list of exceptions if possible.

Parameters:

  • exceptions (Array<Exception>)

Returns:



241
242
243
244
# File 'lib/dry/monads/try.rb', line 241

def Try(*exceptions, &f)
  catchable = exceptions.empty? ? DEFAULT_EXCEPTIONS : exceptions.flatten
  Try.run(catchable, f)
end